summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2013-05-20 06:51:25 +0000
committer Miodrag Milanovic <mmicko@gmail.com>2013-05-20 06:51:25 +0000
commit1c05ccc93bd32a9bb5a50f18e2e8bd29c3511e25 (patch)
tree7133a7cea14e7c27e731c320b87663971b1a31d3
parentcae878c9b438a4b88678db213db9c4aed215b5cc (diff)
Cleanups and version bumpmame0148u5
-rw-r--r--hash/aim65_cart.xml8
-rw-r--r--hash/amiga_flop.xml2
-rw-r--r--hash/c64_cart.xml6
-rw-r--r--hash/cpc_flop.xml24
-rw-r--r--hash/ec1841.xml20
-rw-r--r--hash/ibm5170.xml20
-rw-r--r--hash/mc1502_flop.xml18
-rw-r--r--hash/megadriv.xml14
-rw-r--r--hash/v1050.xml2
-rw-r--r--hash/x68k_flop.xml64
-rw-r--r--src/emu/cpu/cosmac/cosdasm.c46
-rw-r--r--src/emu/cpu/ie15/ie15.c66
-rw-r--r--src/emu/cpu/ie15/ie15.h2
-rw-r--r--src/emu/cpu/ie15/ie15dasm.c118
-rw-r--r--src/emu/debug/debugcmd.c8
-rw-r--r--src/emu/debug/debugcpu.c28
-rw-r--r--src/emu/debug/debugcpu.h10
-rw-r--r--src/emu/emuopts.h8
-rw-r--r--src/emu/luaengine.c58
-rw-r--r--src/emu/luaengine.h14
-rw-r--r--src/emu/machine.c4
-rw-r--r--src/emu/machine.h6
-rw-r--r--src/emu/machine/mcf5206e.c62
-rw-r--r--src/emu/machine/mcf5206e.h8
-rw-r--r--src/emu/machine/pic8259.c1
-rw-r--r--src/emu/machine/spchrom.c2
-rw-r--r--src/emu/machine/upd4701.h2
-rw-r--r--src/emu/sound/2610intf.c2
-rw-r--r--src/emu/sound/2610intf.h2
-rw-r--r--src/emu/sound/3812intf.c2
-rw-r--r--src/emu/sound/8950intf.c2
-rw-r--r--src/emu/sound/qsound.c18
-rw-r--r--src/emu/sound/qsound.h2
-rw-r--r--src/emu/sound/spu.c2
-rw-r--r--src/emu/sound/tms5110.h2
-rw-r--r--src/emu/video/315_5124.c4
-rw-r--r--src/emu/video/pc_vga.c16
-rw-r--r--src/lib/lua/lapi.c1673
-rw-r--r--src/lib/lua/lapi.h6
-rw-r--r--src/lib/lua/lauxlib.c1087
-rw-r--r--src/lib/lua/lauxlib.h86
-rw-r--r--src/lib/lua/lbaselib.c579
-rw-r--r--src/lib/lua/lbitlib.c205
-rw-r--r--src/lib/lua/lcode.c1207
-rw-r--r--src/lib/lua/lcode.h22
-rw-r--r--src/lib/lua/lcorolib.c193
-rw-r--r--src/lib/lua/lctype.c70
-rw-r--r--src/lib/lua/lctype.h53
-rw-r--r--src/lib/lua/ldblib.c525
-rw-r--r--src/lib/lua/ldebug.c807
-rw-r--r--src/lib/lua/ldebug.h14
-rw-r--r--src/lib/lua/ldo.c914
-rw-r--r--src/lib/lua/ldo.h15
-rw-r--r--src/lib/lua/ldump.c184
-rw-r--r--src/lib/lua/lfunc.c193
-rw-r--r--src/lib/lua/lfunc.h10
-rw-r--r--src/lib/lua/lgc.c1486
-rw-r--r--src/lib/lua/lgc.h80
-rw-r--r--src/lib/lua/linit.c51
-rw-r--r--src/lib/lua/liolib.c735
-rw-r--r--src/lib/lua/llex.c715
-rw-r--r--src/lib/lua/llex.h56
-rw-r--r--src/lib/lua/llimits.h124
-rw-r--r--src/lib/lua/lmathlib.c305
-rw-r--r--src/lib/lua/lmem.c77
-rw-r--r--src/lib/lua/lmem.h29
-rw-r--r--src/lib/lua/loadlib.c761
-rw-r--r--src/lib/lua/lobject.c367
-rw-r--r--src/lib/lua/lobject.h429
-rw-r--r--src/lib/lua/lopcodes.c165
-rw-r--r--src/lib/lua/lopcodes.h202
-rw-r--r--src/lib/lua/loslib.c353
-rw-r--r--src/lib/lua/lparser.c2237
-rw-r--r--src/lib/lua/lparser.h118
-rw-r--r--src/lib/lua/lstate.c354
-rw-r--r--src/lib/lua/lstate.h223
-rw-r--r--src/lib/lua/lstring.c189
-rw-r--r--src/lib/lua/lstring.h14
-rw-r--r--src/lib/lua/lstrlib.c1467
-rw-r--r--src/lib/lua/ltable.c720
-rw-r--r--src/lib/lua/ltable.h10
-rw-r--r--src/lib/lua/ltablib.c377
-rw-r--r--src/lib/lua/ltm.c71
-rw-r--r--src/lib/lua/ltm.h46
-rw-r--r--src/lib/lua/lua.c631
-rw-r--r--src/lib/lua/lua.h212
-rw-r--r--src/lib/lua/luac.c612
-rw-r--r--src/lib/lua/luaconf.h215
-rw-r--r--src/lib/lua/lualib.h20
-rw-r--r--src/lib/lua/lundump.c306
-rw-r--r--src/lib/lua/lundump.h4
-rw-r--r--src/lib/lua/lvm.c1419
-rw-r--r--src/lib/lua/lvm.h10
-rw-r--r--src/lib/lua/lzio.c80
-rw-r--r--src/lib/lua/lzio.h30
-rw-r--r--src/lib/util/cdrom.c59
-rw-r--r--src/lib/util/chdcd.c3
-rw-r--r--src/mame/drivers/24cdjuke.c80
-rw-r--r--src/mame/drivers/bfm_sc5.c8
-rw-r--r--src/mame/drivers/bombjack.c10
-rw-r--r--src/mame/drivers/deniam.c2
-rw-r--r--src/mame/drivers/dooyong.c2
-rw-r--r--src/mame/drivers/fcrash.c2
-rw-r--r--src/mame/drivers/flstory.c2
-rw-r--r--src/mame/drivers/fruitpc.c276
-rw-r--r--src/mame/drivers/galaxian.c6
-rw-r--r--src/mame/drivers/galdrvr.c6
-rw-r--r--src/mame/drivers/goldnpkr.c56
-rw-r--r--src/mame/drivers/goldstar.c8
-rw-r--r--src/mame/drivers/jpms80.c2
-rw-r--r--src/mame/drivers/jpmsru.c6
-rw-r--r--src/mame/drivers/m92.c2
-rw-r--r--src/mame/drivers/mpu4hw.c2
-rw-r--r--src/mame/drivers/namcos12.c2
-rw-r--r--src/mame/drivers/nmk16.c18
-rw-r--r--src/mame/drivers/pacman.c12
-rw-r--r--src/mame/drivers/rallyx.c168
-rw-r--r--src/mame/drivers/seabattl.c109
-rw-r--r--src/mame/drivers/snookr10.c50
-rw-r--r--src/mame/drivers/stuntair.c42
-rw-r--r--src/mame/drivers/su2000.c12
-rw-r--r--src/mame/drivers/system16.c6
-rw-r--r--src/mame/drivers/taitogn.c6
-rw-r--r--src/mame/drivers/travrusa.c106
-rw-r--r--src/mame/includes/bfm_sc45.h1
-rw-r--r--src/mame/includes/bfm_sc5.h1
-rw-r--r--src/mame/includes/midtunit.h4
-rw-r--r--src/mame/includes/pgm.h14
-rw-r--r--src/mame/includes/tx1.h4
-rw-r--r--src/mame/includes/zodiack.h1
-rw-r--r--src/mame/machine/megavdp.c2
-rw-r--r--src/mame/machine/naomicrypt.c3
-rw-r--r--src/mame/machine/pgmprot4.c15
-rw-r--r--src/mame/machine/pgmprot6.c50
-rw-r--r--src/mame/mame.lst57
-rw-r--r--src/mame/video/snes.c2
-rw-r--r--src/mame/video/snookr10.c4
-rw-r--r--src/mess/audio/gb.c69
-rw-r--r--src/mess/audio/gb.h8
-rw-r--r--src/mess/audio/lynx.c40
-rw-r--r--src/mess/audio/lynx.h4
-rw-r--r--src/mess/audio/wswan.c6
-rw-r--r--src/mess/drivers/a7800.c2
-rw-r--r--src/mess/drivers/aim65.c22
-rw-r--r--src/mess/drivers/apollo.c12
-rw-r--r--src/mess/drivers/applix.c1
-rw-r--r--src/mess/drivers/d6800.c10
-rw-r--r--src/mess/drivers/esq1.c81
-rw-r--r--src/mess/drivers/horizon.c42
-rw-r--r--src/mess/drivers/ie15.c94
-rw-r--r--src/mess/drivers/microkit.c4
-rw-r--r--src/mess/drivers/ngp.c2
-rw-r--r--src/mess/drivers/pc.c4
-rw-r--r--src/mess/drivers/pet.c2
-rw-r--r--src/mess/drivers/sms.c24
-rw-r--r--src/mess/drivers/softbox.c26
-rw-r--r--src/mess/drivers/ts802.c6
-rw-r--r--src/mess/includes/gb.h14
-rw-r--r--src/mess/includes/lynx.h2
-rw-r--r--src/mess/includes/softbox.h12
-rw-r--r--src/mess/machine/apollo.c2
-rw-r--r--src/mess/machine/gb.c26
-rw-r--r--src/mess/machine/lynx.c6
-rw-r--r--src/mess/machine/md_stm95.h2
-rw-r--r--src/mess/machine/nes_bootleg.c28
-rw-r--r--src/mess/machine/nes_bootleg.h8
-rw-r--r--src/mess/machine/nes_kaiser.c20
-rw-r--r--src/mess/machine/nes_kaiser.h6
-rw-r--r--src/mess/machine/nes_mmc3_clones.c27
-rw-r--r--src/mess/machine/nes_slot.c2
-rw-r--r--src/mess/machine/nes_slot.h2
-rw-r--r--src/mess/machine/pc.c2
-rw-r--r--src/mess/machine/pc_joy_sw.c2
-rw-r--r--src/mess/machine/psxcard.c24
-rw-r--r--src/mess/machine/psxcd.c1
-rw-r--r--src/mess/machine/psxmultitap.h2
-rw-r--r--src/mess/machine/s100_nsmdsa.h2
-rw-r--r--src/mess/machine/s100_nsmdsad.h2
-rw-r--r--src/mess/machine/s100_wunderbus.c6
-rw-r--r--src/mess/machine/sms.c2
-rw-r--r--src/mess/machine/ti99/speech8.h10
-rw-r--r--src/mess/machine/wswan.c8
-rw-r--r--src/mess/video/a7800.c16
-rw-r--r--src/mess/video/apollo.c26
-rw-r--r--src/mess/video/gb.c24
-rw-r--r--src/mess/video/k1ge.c1
-rw-r--r--src/osd/sdl/debugqtdasmwindow.h6
-rw-r--r--src/osd/sdl/debugqtlogwindow.h4
-rw-r--r--src/osd/sdl/debugqtmainwindow.c2
-rw-r--r--src/osd/sdl/debugqtmainwindow.h6
-rw-r--r--src/osd/sdl/debugqtmemorywindow.c14
-rw-r--r--src/osd/sdl/debugqtmemorywindow.h8
-rw-r--r--src/osd/sdl/debugqtview.h4
-rw-r--r--src/osd/sdl/debugqtwindow.h8
-rw-r--r--src/osd/windows/d3d9intf.c1
-rw-r--r--src/osd/windows/d3dcomm.h159
-rw-r--r--src/osd/windows/d3dhlsl.c6
-rw-r--r--src/osd/windows/d3dhlsl.h71
-rw-r--r--src/osd/windows/d3dintf.h1
-rw-r--r--src/osd/windows/drawd3d.c123
-rw-r--r--src/osd/windows/drawd3d.h125
-rw-r--r--src/osd/windows/winmain.c26
-rw-r--r--src/osd/windows/winmain.h4
-rw-r--r--src/tools/chdman.c2
-rw-r--r--src/version.c2
205 files changed, 13141 insertions, 13212 deletions
diff --git a/hash/aim65_cart.xml b/hash/aim65_cart.xml
index 59498663592..0fa9eecd7eb 100644
--- a/hash/aim65_cart.xml
+++ b/hash/aim65_cart.xml
@@ -4,7 +4,7 @@
<!--
- There are 5 ROM sockets on the AIM 65 PCB: 2 sockets were for the boot strap and 3 sockets for software roms,
+ There are 5 ROM sockets on the AIM 65 PCB: 2 sockets were for the boot strap and 3 sockets for software roms,
at locations z24, z25, and z26.
There are the BASIC ROMs, PL65 and FORTH. Each has 2 ROMs and they all work.
@@ -25,7 +25,7 @@
</dataarea>
</part>
</software>
-
+
<software name="basic11">
<description>AIM 65 BASIC v1.1</description>
<year>1978</year>
@@ -59,7 +59,7 @@
</dataarea>
</part>
</software>
-
+
<software name="mathpack" supported="no">
<description>Mathpack</description>
<year>197?</year>
@@ -71,7 +71,7 @@
</dataarea>
</part>
</software>
-
+
<software name="pl65">
<description>AIM 65 PL/65 v1.0</description>
<year>1978</year>
diff --git a/hash/amiga_flop.xml b/hash/amiga_flop.xml
index 30e75a6fa89..02106ae568b 100644
--- a/hash/amiga_flop.xml
+++ b/hash/amiga_flop.xml
@@ -1346,7 +1346,7 @@
</software>
<software name="asspd001a" cloneof="asspd001" supported="no">
- <description>PD Games Volume 001 (Tanx, Roller-Pede, Amigoids, Cave Runner, Avatris) (Alt)</description> <year>199?</year>
+ <description>PD Games Volume 001 (Tanx, Roller-Pede, Amigoids, Cave Runner, Avatris) (Alt)</description> <year>199?</year>
<publisher>The Assassins</publisher>
<part name="flop1" interface="floppy_3_5">
<feature name="part_id" value="Disk 1" />
diff --git a/hash/c64_cart.xml b/hash/c64_cart.xml
index 6d970d8df96..bbe5b94f736 100644
--- a/hash/c64_cart.xml
+++ b/hash/c64_cart.xml
@@ -6344,7 +6344,7 @@
</dataarea>
</part>
</software>
-
+
<software name="codebust">
<description>Codebuster</description>
<year>198?</year>
@@ -6460,12 +6460,12 @@
<year>1989</year>
<publisher>LMS Tech</publisher>
<sharedfeat name="compatibility" value="PAL"/>
-
+
<part name="cart" interface="c64_cart">
<feature name="slot" value="supersnap4" />
<feature name="exrom" value="1" />
<feature name="game" value="1" />
-
+
<dataarea name="roml" size="0x8000">
<rom name="super_snapshot_v4.0_1989_pal.bin" size="0x8000" crc="bf736f28" sha1="6819c655b7b3e08346236f649de5245bc9a41d25" offset="0" />
</dataarea>
diff --git a/hash/cpc_flop.xml b/hash/cpc_flop.xml
index 81ddb02de96..d1dc72417f6 100644
--- a/hash/cpc_flop.xml
+++ b/hash/cpc_flop.xml
@@ -9560,8 +9560,8 @@ stick to CPC-Power disks, when available)
<!-- Identifying Ball Breaker (UK) (1987) [b1].dsk... --> <!-- GoodCPC -->
<!--<software name="ballbrek_b" cloneof="ballbrek" supported="no">
<description>Ball Breaker (UK) [b1]</description>
- <year>1987</year>
- <publisher>CRL Group</publisher>
+ <year>1987</year>
+ <publisher>CRL Group</publisher>
<part name="flop1" interface="floppy_3">
<dataarea name="flop" size="194816">
<rom name="ball breaker (uk) (1987) [b1] (goodcpc).dsk" size="194816" crc="7239c9ab" sha1="bdd14cedc04e174981981d10cc47fc4c9f07b2f2" offset="0" />
@@ -21407,9 +21407,9 @@ stick to CPC-Power disks, when available)
<!-- Identifying Chuckie Egg 2 Compilation Disk 2 (UK) (19xx) [b1].dsk... --> <!-- GoodCPC -->
<!--
<software name="chuckie2_bad" cloneof="chuckie2" supported="no">
- <description>Chuckie Egg 2 (UK, Bad)</description>
- <year>1985</year>
- <publisher>Pick &amp; Choose</publisher>
+ <description>Chuckie Egg 2 (UK, Bad)</description>
+ <year>1985</year>
+ <publisher>Pick &amp; Choose</publisher>
<part name="flop1" interface="floppy_3">
<dataarea name="flop" size="194816">
<rom name="chuckie egg 2 compilation disk 2 (uk) (19xx) [b1] (goodcpc).dsk" size="194816" crc="9ec2c8e9" sha1="ca706de6cf60eb36d9e1de305660b04ca10e383c" offset="0" />
@@ -21513,9 +21513,9 @@ stick to CPC-Power disks, when available)
<!-- Identifying Cine Clap (1986)(Ubi Soft)(fr)(Disk 1 of 2)[b].dsk... --> <!-- Mostly GoodCPC -->
<!--<software name="cineclap_b1" cloneof="cineclap" supported="no">
- <description>Cine Clap (Fra, Disk 1 Bad)</description>
- <year>1986</year>
- <publisher>Ubi Soft</publisher>
+ <description>Cine Clap (Fra, Disk 1 Bad)</description>
+ <year>1986</year>
+ <publisher>Ubi Soft</publisher>
<part name="flop1" interface="floppy_3">
<dataarea name="flop" size="200192">
<rom name="cine clap (1986)(ubi soft)(fr)(disk 1 of 2)[b].dsk" size="200192" crc="973e7bc6" sha1="d5a17b9e35b768a51fc105897ac7987ae44827c2" offset="0" />
@@ -21788,8 +21788,8 @@ stick to CPC-Power disks, when available)
<!-- Identifying Cite Perdue, La (F) (1987) (Disk 3 of 4) [b1].dsk... --> <!-- GoodCPC -->
<!--<software name="citeperd_b1" cloneof="citeperd" supported="no">
<description>La Cite Perdue (Fra, Disk 3 Bad)</description>
- <year>1986</year>
- <publisher>Excalibur</publisher>
+ <year>1986</year>
+ <publisher>Excalibur</publisher>
<part name="flop1" interface="floppy_3">
<dataarea name="flop" size="204559">
<rom name="cite perdue, la (f) (1987) (disk 3 of 4) [b1] (goodcpc).dsk" size="204559" crc="cb59ee1f" sha1="2b992e5e88389719b3fd5ab5448b9ba4fb008f3e" offset="0" />
@@ -21907,8 +21907,8 @@ stick to CPC-Power disks, when available)
<!-- Identifying Clash (F) (1987) (Disk 2 of 2) [b1].dsk... --> <!-- GoodCPC -->
<!--<software name="clash_bf19" supported="no">
<description>Clash (Fra, Bad)</description>
- <year>1987</year>
- <publisher>ERE Informatique</publisher>
+ <year>1987</year>
+ <publisher>ERE Informatique</publisher>
<part name="flop1" interface="floppy_3">
<dataarea name="flop" size="196096">
<rom name="clash (f) (1987) (disk 1 of 2) [b1] (goodcpc).dsk" size="196096" crc="95b33aa0" sha1="9de3499e82eda4b87b6a46dd2452682484ea57cd" offset="0" />
diff --git a/hash/ec1841.xml b/hash/ec1841.xml
index f73ce74b66d..c230d7a2d2d 100644
--- a/hash/ec1841.xml
+++ b/hash/ec1841.xml
@@ -2,16 +2,16 @@
<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
<!--
XXX
- <software name="XXX">
- <description>XXX</description>
- <year>1988</year>
- <publisher>MPO VT</publisher>
- <part name="flop1" interface="floppy_5_25">
- <dataarea name="flop" size="368640">
- </dataarea>
- </part>
- </software>
- XXX
+ <software name="XXX">
+ <description>XXX</description>
+ <year>1988</year>
+ <publisher>MPO VT</publisher>
+ <part name="flop1" interface="floppy_5_25">
+ <dataarea name="flop" size="368640">
+ </dataarea>
+ </part>
+ </software>
+ XXX
-->
<softwarelist name="ec1841" description="EC 1841 disk images">
diff --git a/hash/ibm5170.xml b/hash/ibm5170.xml
index 2dd810157fe..1784536a3fc 100644
--- a/hash/ibm5170.xml
+++ b/hash/ibm5170.xml
@@ -1223,13 +1223,13 @@ Missing files come here
<!-- Coverdisks -->
<!-- Riki (Slovakia) -->
-
+
<!-- Riki 8 undumped
<info name="Contents" value="The Mask" />-->
-
+
<!-- Riki 10 undumped
<info name="Contents" value="Pyrotechnika" />-->
-
+
<!-- Riki 11 undumped
<info name="Contents" value="Super Stardust" />-->
@@ -1256,7 +1256,7 @@ Missing files come here
</dataarea>
</part>
</software>
-
+
<!-- Riki 14 undumped
<info name="Contents" value="Bleifuss" />-->
@@ -1271,22 +1271,22 @@ Missing files come here
</dataarea>
</part>
</software>
-
+
<!-- Riki 16 undumped
<info name="Contents" value="Jungle Book" />-->
-
+
<!-- Riki 17 undumped
<info name="Contents" value="Turrican II" />-->
-
+
<!-- Riki 18 undumped
<info name="Contents" value="Worms />-->
-
+
<!-- Riki 19 undumped
<info name="Contents" value="Tempest 2000" />-->
-
+
<!-- Riki 20 undumped
<info name="Contents" value="Virtual Snooker" />-->
-
+
<!-- Riki 21 undumped
<info name="Contents" value="World Rally Fever" />-->
diff --git a/hash/mc1502_flop.xml b/hash/mc1502_flop.xml
index 1a83ad733ba..e77d298556f 100644
--- a/hash/mc1502_flop.xml
+++ b/hash/mc1502_flop.xml
@@ -3,15 +3,15 @@
<!--
XXX
<software name="XXX">
- <description>XXX</description>
- <year>19??</year>
- <publisher>NPO Microprocessor</publisher>
- <part name="flop1" interface="floppy_5_25">
- <dataarea name="flop" size="368640">
- </dataarea>
- </part>
- </software>
- XXX
+ <description>XXX</description>
+ <year>19??</year>
+ <publisher>NPO Microprocessor</publisher>
+ <part name="flop1" interface="floppy_5_25">
+ <dataarea name="flop" size="368640">
+ </dataarea>
+ </part>
+ </software>
+ XXX
-->
<softwarelist name="mc1502_flop" description="MC 1502 disk images">
diff --git a/hash/megadriv.xml b/hash/megadriv.xml
index 6aaecef6924..bb86816f356 100644
--- a/hash/megadriv.xml
+++ b/hash/megadriv.xml
@@ -380,7 +380,7 @@ Info on Sega chip labels (from Sunbeam / Digital Corruption)
<year>1993</year>
<publisher>Arena Entertainment</publisher>
<part name="cart" interface="megadriv_cart">
- <feature name="pcb" value="670100 REV7" /> <!-- REV1 found in Euro cart -->
+ <feature name="pcb" value="670100 REV7" /> <!-- REV1 found in Euro cart -->
<feature name="ic1" value="MPR-15061-F" />
<dataarea name="rom" size="524288">
<rom name="mpr-15061-f.ic1" size="524288" crc="a3b00d6e" sha1="1f4b969592f98d2692cb06eca550da9c03062593" offset="000000" loadflag="load16_word_swap" />
@@ -2493,7 +2493,7 @@ Info on Sega chip labels (from Sunbeam / Digital Corruption)
ALL RIGHTS RESERVED
S77H81/00000010
9640 D
-
+
[USA, maybe?]
FIFA 97 B1
(c)ELECTRONIC ARTS 1996
@@ -4514,7 +4514,7 @@ Info on Sega chip labels (from Sunbeam / Digital Corruption)
<part name="cart" interface="megadriv_cart">
<feature name="slot" value="rom_nbajam" />
<feature name="pcb" value="670120 REV 2" />
- <feature name="u1" value="NBA JAM GEN VER 1.00" /> <!-- also found pic (from US cart?) with rom marked "GEN NBA JAM 9402 VER 1.00 S285" -->
+ <feature name="u1" value="NBA JAM GEN VER 1.00" /> <!-- also found pic (from US cart?) with rom marked "GEN NBA JAM 9402 VER 1.00 S285" -->
<feature name="u2" value="DV74ALS138N" />
<feature name="u3" value="GD74LS74A" />
<feature name="u4" value="GD74LS125A" />
@@ -7925,10 +7925,10 @@ Info on Sega chip labels (from Sunbeam / Digital Corruption)
<feature name="ic1" value="MPR-19766-MX" />
<feature name="ic2" value="MPR-19767-MX" />
<feature name="ic3" value="LH52B256D-70LL" />
- <feature name="ic4" value="BA6162" /> <!-- On the back of the PCB -->
- <feature name="ic5" value="7C46HC139" /> <!-- On the back of the PCB -->
- <feature name="ic6" value="7B16HC00" /> <!-- On the back of the PCB -->
- <feature name="ic7" value="74HC74A" /> <!-- On the back of the PCB -->
+ <feature name="ic4" value="BA6162" /> <!-- On the back of the PCB -->
+ <feature name="ic5" value="7C46HC139" /> <!-- On the back of the PCB -->
+ <feature name="ic6" value="7B16HC00" /> <!-- On the back of the PCB -->
+ <feature name="ic7" value="74HC74A" /> <!-- On the back of the PCB -->
<feature name="batt" value="(Lithium Cell)" />
<dataarea name="rom" size="3145728">
<rom name="mpr-19766-mx.ic1" size="2097152" crc="99545a01" sha1="f56f4376e45917c875b9286b1bfe90c2b67c29c1" offset="0x000000" loadflag="load16_word_swap" />
diff --git a/hash/v1050.xml b/hash/v1050.xml
index ae4f7a6dee7..ae5f3815de8 100644
--- a/hash/v1050.xml
+++ b/hash/v1050.xml
@@ -123,5 +123,5 @@
</dataarea>
</part>
</software>
-
+
</softwarelist>
diff --git a/hash/x68k_flop.xml b/hash/x68k_flop.xml
index 481fd7ecae8..9bd968a8623 100644
--- a/hash/x68k_flop.xml
+++ b/hash/x68k_flop.xml
@@ -3,16 +3,16 @@
<!--
-Image formats:
+Image formats:
Collections of X68000 disks are available in multiple formats: DIM, FDI, XDF, D88
-* D88 and FDI are very good formats but not widely supported by other X68000 emus
+* D88 and FDI are very good formats but not widely supported by other X68000 emus
(they are typically used for PC88 or PC98 disks)
-* DIM is capable of represent any X68000 disk without protections (6 different disk
+* DIM is capable of represent any X68000 disk without protections (6 different disk
formats, including both 1.2MB and 1.4MB disks with different densities)
* XDF is limited to standard X68000 1.2MB disks without protections and nothing else
-Notice that for standard 1.2MB disks, DIM and XDF are basically equivalent, since the
+Notice that for standard 1.2MB disks, DIM and XDF are basically equivalent, since the
only difference lies in the 0x100 bytes header appended to the DIM files (prescribing
the disk format and the number of used tracks, among other things)
@@ -27,15 +27,15 @@ Exceptions are:
A very nice tool to convert files from a format to the other is VFIC (Virtual Floppy
Image Converter).
A minor bug is present in the program though, when converting *some* images to DIM,
-which has to be taken into account (many thanks to Ashura at the Tokugawa boards for
-explaining the issue and the fix): VFIC sometimes detects 2HS (1.4M) images as 2HC (1.2M)
+which has to be taken into account (many thanks to Ashura at the Tokugawa boards for
+explaining the issue and the fix): VFIC sometimes detects 2HS (1.4M) images as 2HC (1.2M)
and sets the wrong media flag in the header in the conversion from other formats to DIM.
-To check if a 1.4M disk converted to DIM is ok it is enough to check the first byte of
-the DIM file (media flag): if it is 03h (2HDE format), then the image is OK; if it is 02h,
-then it has to be changed to 01h. 2HQ format (media flag 09h) might be affected as well,
-but there seems to be no 2HQ images converted from other formats to DIM, so there should
+To check if a 1.4M disk converted to DIM is ok it is enough to check the first byte of
+the DIM file (media flag): if it is 03h (2HDE format), then the image is OK; if it is 02h,
+then it has to be changed to 01h. 2HQ format (media flag 09h) might be affected as well,
+but there seems to be no 2HQ images converted from other formats to DIM, so there should
be no problematic files.
-An alternate way to check whether the 1.4MB images are correct it is to convert them all
+An alternate way to check whether the 1.4MB images are correct it is to convert them all
to D88 format with VFIC. If the resulting image size is 1.2MB, then it has the wrong flag!
The only protected disks known are (as of now): Might & Magic, Rogue Alliance and Silent Moebius.
@@ -46,10 +46,10 @@ TODO: check the first byte in the 1.44MB images below!!
-->
-<!--
+<!--
Missing dumps
-Arkham Products
+Arkham Products
===============
Floppy Bunko 1 Listeners club 0990 vol.1
Floppy Bunko 11 Listeners club 0990 vol.2
@@ -109,7 +109,7 @@ Ayumi chan Monogatari prototype
Ayumi chan Monogatari Hint Disk
DALK Hint Disk
-Babylon
+Babylon
=======
Pasocomic Purple Cat Vol.2 Hospital Tokushuu
Pasocomic Purple Cat Kokodake no Disk
@@ -218,7 +218,7 @@ Family Soft
===========
Kidou Senshi Gundam Classic Operation Orignal Scenario Disk
-Grocer
+Grocer
======
As you like Yaritaihoudai 3 Europa Tour As You Like
@@ -232,11 +232,11 @@ Shinjuku Monogatari
Yumeji Asakusa Kitan
Koroshi no Dress 3
-JDS
+JDS
===
Meikantoku 2
-Jitensha Sougyou
+Jitensha Sougyou
================
Road Blaster
Sora no Fudousan
@@ -251,7 +251,7 @@ Kure Software Koubou
====================
First Queen
-KD Office
+KD Office
=========
Kage no Subashi Shitehonzon
@@ -272,11 +272,11 @@ MicroProse
==========
F15 Strike Eagle II Sabaku no Arashi Sakusen Scenario Disk
-NIC
+NIC
===
Magic Knight
-New
+New
===
Princess Maker
@@ -284,7 +284,7 @@ New System House Oh!
====================
Tokyo Joshikou Seifuku o Nuida Zukan Part.3
-Nihon Computer Club Renmei Kikaku
+Nihon Computer Club Renmei Kikaku
=================================
Cyber Writer Graphic & Music library Shuu
D-RETURN Tei Nanido Version
@@ -303,7 +303,7 @@ Sharp
=====
Soukoban Revenge SX-68K User no Gyakushuu Hen
-Symphonic Project
+Symphonic Project
=================
Galaxy Mind
@@ -311,16 +311,16 @@ Scap Trust
==========
Shikinjou
-Starcraft
+Starcraft
=========
Might & Magic 2
-Sougou Business Assist
+Sougou Business Assist
======================
Campaign ban Daisenryaku 2 Sakusenbetsu Map
Campaign ban Daisenryaku 2 Unit Kaizou Pack
-Software House Parsley
+Software House Parsley
======================
image 2
Be Rain
@@ -329,12 +329,12 @@ Softhouse Aladdin
=================
QUIZ Ikasete...
-Soft Plan
+Soft Plan
=========
King's Dungeon
Dark Odyssey
-Techno Brain
+Techno Brain
============
Ginga Senshin Guyna Rock
@@ -3220,7 +3220,7 @@ Most info on release dates and Jpn titles come from the following (wonderful) re
</software>
<!--
-According to http://mercenaryforce.web.fc2.com/x68k/x68000/00083.html this game consisted of 4 disks, not 8!
+According to http://mercenaryforce.web.fc2.com/x68k/x68000/00083.html this game consisted of 4 disks, not 8!
maybe the remaining disks are the supposedly undumped addons: Daikairei Powerup kit to Shin Scenario Make kit &amp; Daikairei Tsuika Scenario
-->
<software name="daikaint">
@@ -3711,7 +3711,7 @@ maybe the remaining disks are the supposedly undumped addons: Daikairei Powerup
<rom name="dios (1990)(zain soft)(disk 4 of 4)(disk d).dim" size="1261824" crc="48c84933" sha1="df88e09eb61df27865866c29893669b9aa261bb0" offset="000000" />
</dataarea>
</part>
- <!-- is this really needed? -->
+ <!-- is this really needed? -->
<part name="flop5" interface="floppy_5_25">
<feature name="part_id" value="User Disk" />
<dataarea name="flop" size="1261824">
@@ -12778,7 +12778,7 @@ maybe the remaining disks are the supposedly undumped addons: Daikairei Powerup
</dataarea>
</part>
</software>
-
+
<software name="strider">
<description>Strider Hiryuu</description>
<year>1992</year>
@@ -29951,8 +29951,8 @@ a contest among doujin programmers... -->
</software>
-<!--
-Technically speaking these are invalid XDF files, because they contain more tracks than supported by XDF, while waiting to get (if possible)
+<!--
+Technically speaking these are invalid XDF files, because they contain more tracks than supported by XDF, while waiting to get (if possible)
a DIM dump with DIFC, these are at least confirmed as coming from real disk (by SuperDeadite)
-->
diff --git a/src/emu/cpu/cosmac/cosdasm.c b/src/emu/cpu/cosmac/cosdasm.c
index e411fb0ced9..889605461b6 100644
--- a/src/emu/cpu/cosmac/cosdasm.c
+++ b/src/emu/cpu/cosmac/cosdasm.c
@@ -58,18 +58,18 @@ static UINT32 disassemble(device_t *device, char *buffer, offs_t pc, const UINT8
opram++;
UINT8 opcode = *oprom++;
-
+
switch (opcode)
{
case 0x00: CDP1801_OPCODE("IDL"); break;
- case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
- case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
+ case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
+ case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
CDP1801_OPCODE("LDN R%01X", implied(opcode)); break;
- case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
- case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
+ case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
+ case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
CDP1801_OPCODE("INC R%01X", implied(opcode)); break;
- case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
- case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
+ case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
+ case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
CDP1801_OPCODE("DEC R%01X", implied(opcode)); break;
case 0x30: CDP1801_OPCODE("BR %04X", short_branch(pc, &opram)); break;
case 0x32: CDP1801_OPCODE("BZ %04X", short_branch(pc, &opram)); break;
@@ -85,11 +85,11 @@ static UINT32 disassemble(device_t *device, char *buffer, offs_t pc, const UINT8
case 0x3d: CDP1801_OPCODE("BN2 %04X", short_branch(pc, &opram)); break;
case 0x3e: CDP1801_OPCODE("BN3 %04X", short_branch(pc, &opram)); break;
case 0x3f: CDP1801_OPCODE("BN4 %04X", short_branch(pc, &opram)); break;
- case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47:
- case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
+ case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47:
+ case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
CDP1801_OPCODE("LDA R%01X", implied(opcode)); break;
- case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
- case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
+ case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
+ case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
CDP1801_OPCODE("STR R%01X", implied(opcode)); break;
case 0x61: CDP1801_OPCODE("OUT 1"); break;
case 0x62: CDP1801_OPCODE("OUT 2"); break;
@@ -108,23 +108,23 @@ static UINT32 disassemble(device_t *device, char *buffer, offs_t pc, const UINT8
case 0x70: CDP1801_OPCODE("RET"); flags = DASMFLAG_STEP_OUT; break;
case 0x71: CDP1801_OPCODE("DIS"); flags = DASMFLAG_STEP_OUT; break;
case 0x78: CDP1801_OPCODE("SAV"); break;
- case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
- case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
+ case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
+ case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
CDP1801_OPCODE("GLO R%01X", implied(opcode)); break;
- case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
- case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
+ case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
+ case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
CDP1801_OPCODE("GHI R%01X", implied(opcode)); break;
- case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7:
- case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
+ case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7:
+ case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
CDP1801_OPCODE("PLO R%01X", implied(opcode)); break;
- case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
- case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
+ case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
+ case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
CDP1801_OPCODE("PHI R%01X", implied(opcode)); break;
- case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
- case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf:
+ case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
+ case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf:
CDP1801_OPCODE("SEP R%01X", implied(opcode)); flags = DASMFLAG_STEP_OVER; break;
- case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7:
- case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
+ case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7:
+ case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
CDP1801_OPCODE("SEX R%01X", implied(opcode)); break;
case 0xf0: CDP1801_OPCODE("LDX"); break;
case 0xf1: CDP1801_OPCODE("OR"); break;
diff --git a/src/emu/cpu/ie15/ie15.c b/src/emu/cpu/ie15/ie15.c
index f25122fd474..1a926e895cd 100644
--- a/src/emu/cpu/ie15/ie15.c
+++ b/src/emu/cpu/ie15/ie15.c
@@ -231,24 +231,24 @@ inline void ie15_device::execute_one(int opcode)
switch (opcode & 0xf0)
{
- case 0x00: // add
+ case 0x00: // add
tmp = m_A + get_reg_lo(opcode & 15);
m_A = tmp & 255;
update_flags(m_A);
m_CF = BIT(tmp, 8);
break;
- case 0x10: // jmp
+ case 0x10: // jmp
m_PC.w.l = get_addr(opcode);
-// m_CF = 0;
+// m_CF = 0;
break;
- case 0x20: // ldc
+ case 0x20: // ldc
set_reg(opcode & 15, arg() | (m_PC.w.l & 0xf00));
m_PC.w.l = m_PC.w.l + 1;
-// m_CF = 0;
+// m_CF = 0;
break;
- case 0x40: // dsr
+ case 0x40: // dsr
tmp = get_reg_lo(opcode & 15) - 1;
-// m_CF = BIT(tmp, 8);
+// m_CF = BIT(tmp, 8);
tmp &= 255;
set_reg(opcode & 15, tmp);
update_flags(tmp);
@@ -259,17 +259,17 @@ inline void ie15_device::execute_one(int opcode)
case 0x30:
switch (opcode)
{
- case 0x30: // lca
+ case 0x30: // lca
m_A = arg();
update_flags(m_A);
m_PC.w.l = m_PC.w.l + 1;
break;
- case 0x33: // ral
+ case 0x33: // ral
tmp = m_A;
m_A = (m_A << 1) | BIT(tmp,7);
update_flags(m_A);
break;
- case 0x35: // rar
+ case 0x35: // rar
tmp = m_A;
m_A = (m_A >> 1) | (BIT(tmp,0) ? 0x80 : 0x00);
update_flags(m_A);
@@ -282,9 +282,9 @@ inline void ie15_device::execute_one(int opcode)
case 0x50:
switch (opcode)
{
- case 0x51: // inc
- case 0x50: // isn
- case 0x58: // ise
+ case 0x51: // inc
+ case 0x50: // isn
+ case 0x58: // ise
tmp = m_A + 1;
m_A = tmp & 255;
update_flags(m_A);
@@ -294,9 +294,9 @@ inline void ie15_device::execute_one(int opcode)
if (opcode == 0x58 && !m_ZF)
SKIP_OP(tmp);
break;
- case 0x5b: // dec
- case 0x52: // dsn
- case 0x5a: // dse
+ case 0x5b: // dec
+ case 0x52: // dsn
+ case 0x5a: // dse
tmp = m_A - 1;
m_A = tmp & 255;
update_flags(m_A);
@@ -306,11 +306,11 @@ inline void ie15_device::execute_one(int opcode)
if (opcode == 0x5a && !m_ZF)
SKIP_OP(tmp);
break;
- case 0x5d: // com
+ case 0x5d: // com
m_A ^= 255;
update_flags(m_A);
break;
- case 0x5f: // clr
+ case 0x5f: // clr
m_A = 0;
update_flags(m_A);
break;
@@ -319,11 +319,11 @@ inline void ie15_device::execute_one(int opcode)
break;
};
break;
- case 0x70: // jmi
-// m_CF = 0;
+ case 0x70: // jmi
+// m_CF = 0;
m_PC.w.l = get_reg(opcode & 15);
break;
- case 0x60: // lla
+ case 0x60: // lla
// special case -- port 7
if (opcode == 0x67)
m_A = 255;
@@ -331,7 +331,7 @@ inline void ie15_device::execute_one(int opcode)
m_A = m_io->read_byte(opcode & 15);
update_flags(m_A);
break;
- case 0xf0: // ota
+ case 0xf0: // ota
// special case -- ports 016, 017
if (opcode == 0xfe)
m_RF = 1;
@@ -339,9 +339,9 @@ inline void ie15_device::execute_one(int opcode)
m_RF = 0;
else
m_io->write_byte(opcode & 15, m_A);
-// m_CF = 0;
+// m_CF = 0;
break;
- case 0xc0: // cfl, sfl
+ case 0xc0: // cfl, sfl
switch (opcode)
{
// special case -- accessing control flag 05 resets CF
@@ -354,7 +354,7 @@ inline void ie15_device::execute_one(int opcode)
break;
}
break;
- case 0x80: // sfc, skp, sfs, nop
+ case 0x80: // sfc, skp, sfs, nop
tmp = opcode & 7;
switch (tmp)
{
@@ -377,28 +377,28 @@ inline void ie15_device::execute_one(int opcode)
if (BIT(opcode, 3) && tmp)
SKIP_OP(tmp);
break;
- case 0xb0: // cs
-// m_CF = 0;
+ case 0xb0: // cs
+// m_CF = 0;
if (m_A == get_reg_lo(opcode & 15)) {
m_ZF = 1;
SKIP_OP(tmp);
}
break;
- case 0x90: // and
+ case 0x90: // and
m_A &= get_reg_lo(opcode & 15);
update_flags(m_A);
break;
- case 0xa0: // xor
+ case 0xa0: // xor
m_A ^= get_reg_lo(opcode & 15);
update_flags(m_A);
break;
- case 0xd0: // lda
+ case 0xd0: // lda
m_A = get_reg_lo(opcode & 15);
update_flags(m_A);
break;
- case 0xe0: // sta
+ case 0xe0: // sta
set_reg(opcode & 15, m_A | (m_PC.w.l & 0xf00));
-// m_CF = 0;
+// m_CF = 0;
break;
default:
illegal(opcode);
@@ -437,7 +437,7 @@ inline UINT16 ie15_device::get_reg(UINT8 reg)
inline void ie15_device::set_reg(UINT8 reg, UINT16 val)
{
(m_RF ? m_REGS[16 + reg] : m_REGS[reg]) = val;
-
+
}
inline void ie15_device::update_flags(UINT8 val)
diff --git a/src/emu/cpu/ie15/ie15.h b/src/emu/cpu/ie15/ie15.h
index 2f9616f75a6..cd67a89f71c 100644
--- a/src/emu/cpu/ie15/ie15.h
+++ b/src/emu/cpu/ie15/ie15.h
@@ -73,7 +73,7 @@ protected:
UINT8 m_A;
PAIR m_PC;
- UINT16 m_REGS[32]; // General registers (2 pages of 16)
+ UINT16 m_REGS[32]; // General registers (2 pages of 16)
UINT8 m_CF; // Carry flag
UINT8 m_ZF; // Zero flag
UINT8 m_RF; // Current register page
diff --git a/src/emu/cpu/ie15/ie15dasm.c b/src/emu/cpu/ie15/ie15dasm.c
index 7c2da4a55c8..4f1e7b40385 100644
--- a/src/emu/cpu/ie15/ie15dasm.c
+++ b/src/emu/cpu/ie15/ie15dasm.c
@@ -12,112 +12,112 @@ CPU_DISASSEMBLE( ie15 )
op = OP(pc++);
switch (op & 0xf0)
{
- case 0x00:
- sprintf (buffer,"add r%d", op & 0x0f);
+ case 0x00:
+ sprintf (buffer,"add r%d", op & 0x0f);
break;
- case 0x10:
- sprintf (buffer,"jmp $%04x", (((op & 0x0f) << 8) | ARG(pc)) + 1);
- pc+=1;
+ case 0x10:
+ sprintf (buffer,"jmp $%04x", (((op & 0x0f) << 8) | ARG(pc)) + 1);
+ pc+=1;
break;
- case 0x20:
- sprintf (buffer,"ldc r%d, #$%02x", (op & 0x0f), ARG(pc));
- pc+=1;
+ case 0x20:
+ sprintf (buffer,"ldc r%d, #$%02x", (op & 0x0f), ARG(pc));
+ pc+=1;
break;
case 0x30: switch (op)
{
- case 0x30:
- sprintf (buffer,"lca #$%02x", ARG(pc));
+ case 0x30:
+ sprintf (buffer,"lca #$%02x", ARG(pc));
pc+=1;
break;
- case 0x33:
- sprintf (buffer,"ral");
+ case 0x33:
+ sprintf (buffer,"ral");
break;
- case 0x35:
- sprintf (buffer,"rar");
+ case 0x35:
+ sprintf (buffer,"rar");
break;
default:
sprintf (buffer,"illegal");
break;
- };
+ };
break;
- case 0x40:
- sprintf (buffer,"dsr r%d", op & 0x0f);
+ case 0x40:
+ sprintf (buffer,"dsr r%d", op & 0x0f);
break;
case 0x50: switch (op)
{
- case 0x50:
- sprintf (buffer,"isn");
+ case 0x50:
+ sprintf (buffer,"isn");
break;
- case 0x51:
- sprintf (buffer,"inc");
+ case 0x51:
+ sprintf (buffer,"inc");
break;
- case 0x52:
- sprintf (buffer,"dsn");
+ case 0x52:
+ sprintf (buffer,"dsn");
break;
- case 0x58:
- sprintf (buffer,"ise");
+ case 0x58:
+ sprintf (buffer,"ise");
break;
- case 0x5a:
- sprintf (buffer,"dse");
+ case 0x5a:
+ sprintf (buffer,"dse");
break;
- case 0x5b:
- sprintf (buffer,"dec");
+ case 0x5b:
+ sprintf (buffer,"dec");
break;
- case 0x5d:
- sprintf (buffer,"com");
+ case 0x5d:
+ sprintf (buffer,"com");
break;
- case 0x5f:
- sprintf (buffer,"clr");
+ case 0x5f:
+ sprintf (buffer,"clr");
break;
default:
sprintf (buffer,"illegal");
break;
- };
+ };
break;
- case 0x60:
- sprintf (buffer,"lla #$%02x", op & 0x0f);
+ case 0x60:
+ sprintf (buffer,"lla #$%02x", op & 0x0f);
break;
- case 0x70:
- sprintf (buffer,"jmi r%d", op & 0x0f);
+ case 0x70:
+ sprintf (buffer,"jmi r%d", op & 0x0f);
break;
case 0x80: switch (op)
{
case 0x80: case 0x81: case 0x82: case 0x83:
case 0x84: case 0x85: case 0x86:
- sprintf (buffer,"sfc #%d", op & 0x07);
+ sprintf (buffer,"sfc #%d", op & 0x07);
break;
- case 0x87:
- sprintf (buffer,"skp");
+ case 0x87:
+ sprintf (buffer,"skp");
break;
case 0x88: case 0x89: case 0x8a: case 0x8b:
case 0x8c: case 0x8d: case 0x8e:
- sprintf (buffer,"sfs #%d", op & 0x07);
+ sprintf (buffer,"sfs #%d", op & 0x07);
break;
- case 0x8f:
- sprintf (buffer,"nop");
+ case 0x8f:
+ sprintf (buffer,"nop");
break;
- };
+ };
break;
- case 0x90:
- sprintf (buffer,"and r%d", op & 0x0f);
+ case 0x90:
+ sprintf (buffer,"and r%d", op & 0x0f);
break;
- case 0xa0:
- sprintf (buffer,"xor r%d", op & 0x0f);
+ case 0xa0:
+ sprintf (buffer,"xor r%d", op & 0x0f);
break;
- case 0xb0:
- sprintf (buffer,"cs r%d", op & 0x0f);
+ case 0xb0:
+ sprintf (buffer,"cs r%d", op & 0x0f);
break;
- case 0xc0:
- sprintf (buffer,"%s #%d", BIT(op, 3) ? "sfl" : "cfl", op & 0x07);
+ case 0xc0:
+ sprintf (buffer,"%s #%d", BIT(op, 3) ? "sfl" : "cfl", op & 0x07);
break;
- case 0xd0:
- sprintf (buffer,"lda r%d", op & 0x0f);
+ case 0xd0:
+ sprintf (buffer,"lda r%d", op & 0x0f);
break;
- case 0xe0:
- sprintf (buffer,"sta r%d", op & 0x0f);
+ case 0xe0:
+ sprintf (buffer,"sta r%d", op & 0x0f);
break;
- case 0xf0:
- sprintf (buffer,"ota #$%02x", op & 0x0f);
+ case 0xf0:
+ sprintf (buffer,"ota #$%02x", op & 0x0f);
break;
}
return (pc - PC) | flags | DASMFLAG_SUPPORTED;
diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c
index 6622f61fafc..06b37a6826e 100644
--- a/src/emu/debug/debugcmd.c
+++ b/src/emu/debug/debugcmd.c
@@ -1721,7 +1721,7 @@ static void execute_stateload(running_machine &machine, int ref, int params, con
{
astring filename(param[0]);
machine.immediate_load(filename);
-
+
// Clear all PC & memory tracks
device_iterator iter(machine.root_device());
for (device_t *device = iter.first(); device != NULL; device = iter.next())
@@ -2802,9 +2802,9 @@ static void execute_pcatmem(running_machine &machine, int ref, int params, const
// Get the value of memory at the address
const int nativeDataWidth = space->data_width() / 8;
const UINT64 data = debug_read_memory(*space,
- space->address_to_byte(address),
- nativeDataWidth,
- true);
+ space->address_to_byte(address),
+ nativeDataWidth,
+ true);
// Recover the pc & print
const address_spacenum spaceNum = (address_spacenum)ref;
diff --git a/src/emu/debug/debugcpu.c b/src/emu/debug/debugcpu.c
index 3c52455b74e..4101a0307a4 100644
--- a/src/emu/debug/debugcpu.c
+++ b/src/emu/debug/debugcpu.c
@@ -2647,9 +2647,9 @@ void device_debug::set_track_pc_visited(const offs_t& pc)
// 'not available'.
//-------------------------------------------------
-offs_t device_debug::track_mem_pc_from_space_address_data(const address_spacenum& space,
- const offs_t& address,
- const UINT64& data) const
+offs_t device_debug::track_mem_pc_from_space_address_data(const address_spacenum& space,
+ const offs_t& address,
+ const UINT64& data) const
{
const offs_t missing = (offs_t)(-1);
if (m_track_mem_set.empty())
@@ -2702,7 +2702,7 @@ bool device_debug::comment_remove(offs_t addr)
const char *device_debug::comment_text(offs_t addr) const
{
- const UINT32 crc = compute_opcode_crc32(addr);
+ const UINT32 crc = compute_opcode_crc32(addr);
dasm_comment* comment = m_comment_set.find(dasm_comment(addr, crc, "", 0));
if (comment == NULL) return NULL;
return comment->m_text;
@@ -3553,7 +3553,7 @@ void device_debug::tracer::flush()
device_debug::dasm_pc_tag::dasm_pc_tag(const offs_t& address, const UINT32& crc)
: m_address(address),
- m_crc(crc)
+ m_crc(crc)
{
}
@@ -3561,14 +3561,14 @@ device_debug::dasm_pc_tag::dasm_pc_tag(const offs_t& address, const UINT32& crc)
// dasm_memory_access - constructor
//-------------------------------------------------
-device_debug::dasm_memory_access::dasm_memory_access(const address_spacenum& address_space,
- const offs_t& address,
- const UINT64& data,
- const offs_t& pc)
+device_debug::dasm_memory_access::dasm_memory_access(const address_spacenum& address_space,
+ const offs_t& address,
+ const UINT64& data,
+ const offs_t& pc)
: m_address_space(address_space),
- m_address(address),
- m_data(data),
- m_pc(pc)
+ m_address(address),
+ m_data(data),
+ m_pc(pc)
{
}
@@ -3578,7 +3578,7 @@ device_debug::dasm_memory_access::dasm_memory_access(const address_spacenum& add
device_debug::dasm_comment::dasm_comment(offs_t address, UINT32 crc, const char *text, rgb_t color)
: dasm_pc_tag(address, crc),
- m_text(text),
- m_color(color)
+ m_text(text),
+ m_color(color)
{
}
diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h
index 75589ac6bc7..97da6ede8e6 100644
--- a/src/emu/debug/debugcpu.h
+++ b/src/emu/debug/debugcpu.h
@@ -261,7 +261,7 @@ public:
// memory tracking
void set_track_mem(bool value) { m_track_mem = value; }
offs_t track_mem_pc_from_space_address_data(const address_spacenum& space,
- const offs_t& address,
+ const offs_t& address,
const UINT64& data) const;
void track_mem_data_clear() { m_track_mem_set.clear(); }
@@ -410,10 +410,10 @@ private:
class dasm_memory_access
{
public:
- dasm_memory_access(const address_spacenum& address_space,
- const offs_t& address,
- const UINT64& data,
- const offs_t& pc);
+ dasm_memory_access(const address_spacenum& address_space,
+ const offs_t& address,
+ const UINT64& data,
+ const offs_t& pc);
// required to be included in a simple_set
bool operator < (const dasm_memory_access& rhs) const
diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h
index 8e95d9124b1..3af5dad2022 100644
--- a/src/emu/emuopts.h
+++ b/src/emu/emuopts.h
@@ -199,9 +199,9 @@ enum
#define OPTION_CONFIRM_QUIT "confirm_quit"
#define OPTION_UI_MOUSE "ui_mouse"
-#define OPTION_AUTOBOOT_COMMAND "autoboot_command"
-#define OPTION_AUTOBOOT_DELAY "autoboot_delay"
-#define OPTION_AUTOBOOT_SCRIPT "autoboot_script"
+#define OPTION_AUTOBOOT_COMMAND "autoboot_command"
+#define OPTION_AUTOBOOT_DELAY "autoboot_delay"
+#define OPTION_AUTOBOOT_SCRIPT "autoboot_script"
//**************************************************************************
// TYPE DEFINITIONS
@@ -355,7 +355,7 @@ public:
bool confirm_quit() const { return bool_value(OPTION_CONFIRM_QUIT); }
bool ui_mouse() const { return bool_value(OPTION_UI_MOUSE); }
-
+
const char *autoboot_command() const { return value(OPTION_AUTOBOOT_COMMAND); }
int autoboot_delay() const { return int_value(OPTION_AUTOBOOT_DELAY); }
const char *autoboot_script() const { return value(OPTION_AUTOBOOT_SCRIPT); }
diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c
index 132aa52da75..ba220907276 100644
--- a/src/emu/luaengine.c
+++ b/src/emu/luaengine.c
@@ -53,7 +53,7 @@ lua_engine* lua_engine::luaThis = NULL;
// emu_gamename - returns game full name
//-------------------------------------------------
-int lua_engine::emu_gamename(lua_State *L)
+int lua_engine::emu_gamename(lua_State *L)
{
lua_pushstring(L, luaThis->machine().system().description);
return 1;
@@ -63,7 +63,7 @@ int lua_engine::emu_gamename(lua_State *L)
// emu_keypost - post keys to natural keyboard
//-------------------------------------------------
-int lua_engine::emu_keypost(lua_State *L)
+int lua_engine::emu_keypost(lua_State *L)
{
const char *keys = luaL_checkstring(L,1);
luaThis->machine().ioport().natkeyboard().post_utf8(keys);
@@ -72,9 +72,9 @@ int lua_engine::emu_keypost(lua_State *L)
static const struct luaL_Reg emu_funcs [] =
{
- { "gamename", lua_engine::emu_gamename },
- { "keypost", lua_engine::emu_keypost },
- { NULL, NULL } /* sentinel */
+ { "gamename", lua_engine::emu_gamename },
+ { "keypost", lua_engine::emu_keypost },
+ { NULL, NULL } /* sentinel */
};
//-------------------------------------------------
@@ -83,8 +83,8 @@ static const struct luaL_Reg emu_funcs [] =
int luaopen_emu ( lua_State * L )
{
- luaL_newlib(L, emu_funcs);
- return 1;
+ luaL_newlib(L, emu_funcs);
+ return 1;
}
//-------------------------------------------------
@@ -94,7 +94,7 @@ int luaopen_emu ( lua_State * L )
void hook(lua_State* l, lua_Debug* ar)
{
- lua_yield(l, 0);
+ lua_yield(l, 0);
}
//-------------------------------------------------
@@ -133,9 +133,9 @@ void lua_engine::initialize()
void lua_engine::close()
{
if (m_lua_state) {
- // close the Lua state
+ // close the Lua state
lua_close(m_lua_state);
- mame_printf_verbose("[LUA] End executing script\n");
+ mame_printf_verbose("[LUA] End executing script\n");
m_lua_state = NULL;
}
}
@@ -146,12 +146,12 @@ void lua_engine::close()
void lua_engine::report_errors(int status)
{
- if ( status!=0 ) {
- mame_printf_error("[LUA ERROR] %s\n",lua_tostring(m_lua_state, -1));
- lua_pop(m_lua_state, 1); // remove error message
-
+ if ( status!=0 ) {
+ mame_printf_error("[LUA ERROR] %s\n",lua_tostring(m_lua_state, -1));
+ lua_pop(m_lua_state, 1); // remove error message
+
close(); // close in case of error
- }
+ }
}
//-------------------------------------------------
@@ -161,12 +161,12 @@ void lua_engine::report_errors(int status)
void lua_engine::createvm()
{
close();
-
- // create new Lua state
- m_lua_state = luaL_newstate();
+
+ // create new Lua state
+ m_lua_state = luaL_newstate();
luaL_openlibs(m_lua_state);
- luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);
- lua_sethook(m_lua_state, hook, LUA_MASKLINE, 0);
+ luaL_requiref(m_lua_state, "emu", luaopen_emu, 1);
+ lua_sethook(m_lua_state, hook, LUA_MASKLINE, 0);
}
//-------------------------------------------------
@@ -175,9 +175,9 @@ void lua_engine::createvm()
void lua_engine::execute(const char *filename)
{
- createvm();
-
- int s = luaL_loadfile(m_lua_state, filename);
+ createvm();
+
+ int s = luaL_loadfile(m_lua_state, filename);
report_errors(s);
mame_printf_verbose("[LUA] Start executing script\n");
@@ -189,9 +189,9 @@ void lua_engine::execute(const char *filename)
void lua_engine::execute_string(const char *value)
{
- createvm();
-
- int s = luaL_loadstring(m_lua_state, value);
+ createvm();
+
+ int s = luaL_loadstring(m_lua_state, value);
report_errors(s);
mame_printf_verbose("[LUA] Start executing script\n");
@@ -204,11 +204,11 @@ void lua_engine::execute_string(const char *value)
void lua_engine::lua_execute()
{
if (m_lua_state==NULL) return;
-
+
int s = lua_resume(m_lua_state, m_lua_state, 0);
-
+
if (s != LUA_YIELD) {
- report_errors(s);
+ report_errors(s);
close();
}
}
diff --git a/src/emu/luaengine.h b/src/emu/luaengine.h
index 0375312228a..6bf2217cc75 100644
--- a/src/emu/luaengine.h
+++ b/src/emu/luaengine.h
@@ -61,20 +61,20 @@ public:
void initialize();
void lua_execute();
void report_errors(int status);
-
+
void createvm();
- void execute(const char *filename);
+ void execute(const char *filename);
void execute_string(const char *value);
void close();
-
- //static
+
+ //static
static int emu_gamename(lua_State *L);
static int emu_keypost(lua_State *L);
-private:
+private:
// internal state
running_machine & m_machine; // reference to our machine
- lua_State* m_lua_state;
-
+ lua_State* m_lua_state;
+
static lua_engine* luaThis;
};
diff --git a/src/emu/machine.c b/src/emu/machine.c
index 8c9ac74acdc..4e5d12910cf 100644
--- a/src/emu/machine.c
+++ b/src/emu/machine.c
@@ -896,9 +896,9 @@ void running_machine::soft_reset(void *ptr, INT32 param)
// setup autoboot if needed
m_autoboot_timer->adjust(attotime(options().autoboot_delay(),0),0);
-
+
// now we're running
- m_current_phase = MACHINE_PHASE_RUNNING;
+ m_current_phase = MACHINE_PHASE_RUNNING;
}
diff --git a/src/emu/machine.h b/src/emu/machine.h
index ffdaa8a7e39..a211a4bddaa 100644
--- a/src/emu/machine.h
+++ b/src/emu/machine.h
@@ -333,7 +333,7 @@ private:
void stop_all_devices();
void presave_all_devices();
void postload_all_devices();
-
+
TIMER_CALLBACK_MEMBER(autoboot_callback);
// internal state
@@ -421,8 +421,8 @@ private:
memory_manager m_memory; // memory manager
ioport_manager m_ioport; // I/O port manager
device_scheduler m_scheduler; // scheduler object
- emu_timer *m_autoboot_timer; // autoboot timer
- lua_engine m_lua_engine; // LUA engine
+ emu_timer *m_autoboot_timer; // autoboot timer
+ lua_engine m_lua_engine; // LUA engine
};
diff --git a/src/emu/machine/mcf5206e.c b/src/emu/machine/mcf5206e.c
index fe5e0b30749..2679a7b62cb 100644
--- a/src/emu/machine/mcf5206e.c
+++ b/src/emu/machine/mcf5206e.c
@@ -18,10 +18,10 @@ void CLIB_DECL nolog(const char *format, ...) {}
#define debuglogtimer nolog
static ADDRESS_MAP_START( coldfire_regs_map, AS_0, 32, mcf5206e_peripheral_device )
-
-
+
+
AM_RANGE(0x014, 0x017) AM_READWRITE8(ICR1_ICR2_ICR3_ICR4_r, ICR1_ICR2_ICR3_ICR4_w, 0xffffffff)
-
+
AM_RANGE(0x01c, 0x01f) AM_READWRITE8(ICR9_ICR10_ICR11_ICR12_r, ICR9_ICR10_ICR11_ICR12_w, 0xffffffff)
AM_RANGE(0x020, 0x023) AM_READWRITE8(ICR13_r, ICR13_w, 0xffffffff)
@@ -64,7 +64,7 @@ static ADDRESS_MAP_START( coldfire_regs_map, AS_0, 32, mcf5206e_peripheral_devic
AM_RANGE(0x1c4, 0x1c7) AM_READWRITE8(PPDDR_r, PPDDR_w, 0xffffffff)
AM_RANGE(0x1c8, 0x1cb) AM_READWRITE8(PPDAT_r, PPDAT_w, 0xffffffff)
-
+
AM_RANGE(0x1e4, 0x1e7) AM_READWRITE8(MFDR_r, MFDR_w, 0xffffffff)
AM_RANGE(0x1e8, 0x1eb) AM_READWRITE8(MBCR_r, MBCR_w, 0xffffffff)
AM_RANGE(0x1ec, 0x1ef) AM_READWRITE8(MBSR_r, MBSR_w, 0xffffffff)
@@ -651,7 +651,7 @@ WRITE16_MEMBER( mcf5206e_peripheral_device::IMR_w)
void mcf5206e_peripheral_device::ICR_info(UINT8 ICR)
{
- debuglog(" (AutoVector) AVEC : %01x | ", (ICR&0x80)>>7);
+ debuglog(" (AutoVector) AVEC : %01x | ", (ICR&0x80)>>7);
debuglog("(Interrupt Level) IL : %01x | ", (ICR&0x1c)>>2); // if autovector (AVEC) is used then the vectors referenced are at +24 (+0x18) + IL, ie the standard 68k autovectors, otherwise vector must be provided by device
debuglog("(Interrupt Priority) IP : %01x |", (ICR&0x03)>>0);
debuglog("(Unused bits) : %01x\n", (ICR&0x60)>>5);
@@ -671,7 +671,7 @@ TIMER_CALLBACK_MEMBER(mcf5206e_peripheral_device::timer1_callback)
debuglogtimer("timer1_callback\n");
m_TER1 |= 0x02;
-
+
timer1->adjust(attotime::from_msec(10)); // completely made up value just to fire our timers for now
}
@@ -699,8 +699,8 @@ WRITE16_MEMBER( mcf5206e_peripheral_device::TMR1_w)
COMBINE_DATA(&m_TMR1);
debuglogtimer("%s: (Timer 1 Mode Register) TMR1_w %04x %04x\n", this->machine().describe_context(), data, mem_mask);
- debuglogtimer(" (Prescale) PS : %02x (Capture Edge/Interrupt) CE : %01x (Output Mode) OM : %01x (Output Reference Interrupt En) ORI : %01x Free Run (FRR) : %01x Input Clock Source (ICLK) : %01x (Reset Timer) RST : %01x \n", (m_TMR1 & 0xff00)>>8, (m_TMR1 & 0x00c0)>>6, (m_TMR1 & 0x0020)>>5, (m_TMR1 & 0x0010)>>4, (m_TMR1 & 0x0008)>>3, (m_TMR1 & 0x0006)>>1, (m_TMR1 & 0x0001)>>0);
-
+ debuglogtimer(" (Prescale) PS : %02x (Capture Edge/Interrupt) CE : %01x (Output Mode) OM : %01x (Output Reference Interrupt En) ORI : %01x Free Run (FRR) : %01x Input Clock Source (ICLK) : %01x (Reset Timer) RST : %01x \n", (m_TMR1 & 0xff00)>>8, (m_TMR1 & 0x00c0)>>6, (m_TMR1 & 0x0020)>>5, (m_TMR1 & 0x0010)>>4, (m_TMR1 & 0x0008)>>3, (m_TMR1 & 0x0006)>>1, (m_TMR1 & 0x0001)>>0);
+
if (m_TMR1 & 0x0001)
{
timer1->adjust(attotime::from_seconds(1)); // completely made up value just to fire our timers for now
@@ -709,8 +709,8 @@ WRITE16_MEMBER( mcf5206e_peripheral_device::TMR1_w)
{
timer1->adjust(attotime::never);
}
-
-
+
+
break;
case 1:
invalidlog("%s: invalid TMR1_w %d, %04x %04x\n", this->machine().describe_context(), offset, data, mem_mask);
@@ -830,8 +830,8 @@ const device_type MCF5206E_PERIPHERAL = &device_creator<mcf5206e_peripheral_devi
mcf5206e_peripheral_device::mcf5206e_peripheral_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, MCF5206E_PERIPHERAL, "MCF5206E Peripheral", tag, owner, clock),
- device_memory_interface(mconfig, *this),
- m_space_config("coldfire_regs", ENDIANNESS_BIG, 32,10, 0, NULL, *ADDRESS_MAP_NAME(coldfire_regs_map))
+ device_memory_interface(mconfig, *this),
+ m_space_config("coldfire_regs", ENDIANNESS_BIG, 32,10, 0, NULL, *ADDRESS_MAP_NAME(coldfire_regs_map))
{
}
@@ -915,31 +915,31 @@ READ32_MEMBER(mcf5206e_peripheral_device::seta2_coldfire_regs_r)
void mcf5206e_peripheral_device::init_regs(bool first_init)
{
- m_ICR[ICR1] = 0x04;
- m_ICR[ICR2] = 0x08;
- m_ICR[ICR3] = 0x0C;
- m_ICR[ICR4] = 0x10;
- m_ICR[ICR5] = 0x14;
- m_ICR[ICR6] = 0x18;
- m_ICR[ICR7] = 0x1C;
- m_ICR[ICR8] = 0x1C;
- m_ICR[ICR9] = 0x80;
- m_ICR[ICR10] = 0x80;
- m_ICR[ICR11] = 0x80;
- m_ICR[ICR12] = 0x00;
- m_ICR[ICR13] = 0x00;
-
- m_CSAR[0] = 0x0000;
- m_CSMR[0] = 0x00000000;
+ m_ICR[ICR1] = 0x04;
+ m_ICR[ICR2] = 0x08;
+ m_ICR[ICR3] = 0x0C;
+ m_ICR[ICR4] = 0x10;
+ m_ICR[ICR5] = 0x14;
+ m_ICR[ICR6] = 0x18;
+ m_ICR[ICR7] = 0x1C;
+ m_ICR[ICR8] = 0x1C;
+ m_ICR[ICR9] = 0x80;
+ m_ICR[ICR10] = 0x80;
+ m_ICR[ICR11] = 0x80;
+ m_ICR[ICR12] = 0x00;
+ m_ICR[ICR13] = 0x00;
+
+ m_CSAR[0] = 0x0000;
+ m_CSMR[0] = 0x00000000;
m_CSCR[0] = 0x3C1F; /* 3C1F, 3C5F, 3C9F, 3CDF, 3D1F, 3D5F, 3D9F, 3DDF | AA set by IRQ 7 at reset, PS1 set by IRQ 4 at reset, PS0 set by IRQ 1 at reset*/
if (first_init)
{
for (int x=1;x<8;x++)
{
- m_CSAR[1] = UNINIT;
- m_CSMR[1] = UNINIT;
- m_CSCR[1] = UNINIT_NOTE; // except BRST=ASET=WRAH=RDAH=WR=RD=0
+ m_CSAR[1] = UNINIT;
+ m_CSMR[1] = UNINIT;
+ m_CSCR[1] = UNINIT_NOTE; // except BRST=ASET=WRAH=RDAH=WR=RD=0
}
}
diff --git a/src/emu/machine/mcf5206e.h b/src/emu/machine/mcf5206e.h
index 6221f11d279..8bda69d7cfb 100644
--- a/src/emu/machine/mcf5206e.h
+++ b/src/emu/machine/mcf5206e.h
@@ -50,7 +50,7 @@ class mcf5206e_peripheral_device : public device_t,
public:
// construction/destruction
mcf5206e_peripheral_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
-
+
void ICR_info(UINT8 ICR);
DECLARE_READ32_MEMBER( dev_r );
@@ -153,9 +153,9 @@ public:
DECLARE_WRITE8_MEMBER( MFDR_w );
DECLARE_READ8_MEMBER( MBDR_r );
DECLARE_WRITE8_MEMBER( MBDR_w );
-
-
+
+
cpu_device* m_cpu;
@@ -171,7 +171,7 @@ protected:
private:
-
+
void init_regs(bool first_init);
UINT8 m_ICR[MAX_ICR];
diff --git a/src/emu/machine/pic8259.c b/src/emu/machine/pic8259.c
index c6a2e4473de..3f96d96734c 100644
--- a/src/emu/machine/pic8259.c
+++ b/src/emu/machine/pic8259.c
@@ -447,4 +447,3 @@ pic8259_device::pic8259_device(const machine_config &mconfig, const char *tag, d
, m_read_slave_ack_func(*this)
{
}
-
diff --git a/src/emu/machine/spchrom.c b/src/emu/machine/spchrom.c
index a7c3d75988e..37678a9296d 100644
--- a/src/emu/machine/spchrom.c
+++ b/src/emu/machine/spchrom.c
@@ -10,7 +10,7 @@
This file is designed to be interfaced with the tms5220 core.
Interfacing it with the tms5110 would make sense, too.
- TODO:
+ TODO:
Create seperate devices for TMS6100 & TMS6125
Implement the serial protocol
*/
diff --git a/src/emu/machine/upd4701.h b/src/emu/machine/upd4701.h
index b169d74d445..cf3af3357d3 100644
--- a/src/emu/machine/upd4701.h
+++ b/src/emu/machine/upd4701.h
@@ -29,7 +29,7 @@ public:
DECLARE_WRITE_LINE_MEMBER( ul_w );
DECLARE_WRITE_LINE_MEMBER( resetx_w );
DECLARE_WRITE_LINE_MEMBER( resety_w );
-
+
DECLARE_READ16_MEMBER( d_r );
DECLARE_READ_LINE_MEMBER( cf_r );
DECLARE_READ_LINE_MEMBER( sf_r );
diff --git a/src/emu/sound/2610intf.c b/src/emu/sound/2610intf.c
index 654cf79e8f0..2b11e740528 100644
--- a/src/emu/sound/2610intf.c
+++ b/src/emu/sound/2610intf.c
@@ -150,7 +150,7 @@ void ym2610_device::device_start()
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
-
+
int rate = clock()/72;
void *pcmbufa,*pcmbufb;
int pcmsizea,pcmsizeb;
diff --git a/src/emu/sound/2610intf.h b/src/emu/sound/2610intf.h
index 34f5faa2071..ac29f88efa6 100644
--- a/src/emu/sound/2610intf.h
+++ b/src/emu/sound/2610intf.h
@@ -38,7 +38,7 @@ protected:
virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
-
+
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
diff --git a/src/emu/sound/3812intf.c b/src/emu/sound/3812intf.c
index 9bf31c13122..e901e6e5e27 100644
--- a/src/emu/sound/3812intf.c
+++ b/src/emu/sound/3812intf.c
@@ -146,7 +146,7 @@ WRITE8_MEMBER( ym3812_device::write )
READ8_MEMBER( ym3812_device::status_port_r ) { return read(space, 0); }
READ8_MEMBER( ym3812_device::read_port_r ) { return read(space, 1); }
WRITE8_MEMBER( ym3812_device::control_port_w ) { write(space, 0, data); }
-WRITE8_MEMBER( ym3812_device::write_port_w ) { write( space, 1, data); }
+WRITE8_MEMBER( ym3812_device::write_port_w ) { write( space, 1, data); }
const device_type YM3812 = &device_creator<ym3812_device>;
diff --git a/src/emu/sound/8950intf.c b/src/emu/sound/8950intf.c
index 664df2d7d41..684c74ac6aa 100644
--- a/src/emu/sound/8950intf.c
+++ b/src/emu/sound/8950intf.c
@@ -39,7 +39,7 @@ void y8950_device::device_timer(emu_timer &timer, device_timer_id id, int param,
case 0:
y8950_timer_over(m_chip,0);
break;
-
+
case 1:
y8950_timer_over(m_chip,1);
break;
diff --git a/src/emu/sound/qsound.c b/src/emu/sound/qsound.c
index dbc1ccc61c5..9fd4dc7657a 100644
--- a/src/emu/sound/qsound.c
+++ b/src/emu/sound/qsound.c
@@ -87,15 +87,15 @@ ROM_END
qsound_device::qsound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, QSOUND, "Q-Sound", tag, owner, clock, "qsound", __FILE__),
- device_sound_interface(mconfig, *this),
- m_data(0),
- m_stream(NULL),
- m_sample_rom_length(0),
- m_sample_rom(NULL),
- m_cpu(NULL),
- m_frq_ratio(0.0f),
- m_fpRawDataL(NULL),
- m_fpRawDataR(NULL)
+ device_sound_interface(mconfig, *this),
+ m_data(0),
+ m_stream(NULL),
+ m_sample_rom_length(0),
+ m_sample_rom(NULL),
+ m_cpu(NULL),
+ m_frq_ratio(0.0f),
+ m_fpRawDataL(NULL),
+ m_fpRawDataR(NULL)
{
}
diff --git a/src/emu/sound/qsound.h b/src/emu/sound/qsound.h
index 396c4a16b85..1c477136125 100644
--- a/src/emu/sound/qsound.h
+++ b/src/emu/sound/qsound.h
@@ -57,7 +57,7 @@ struct QSOUND_CHANNEL
// ======================> qsound_device
class qsound_device : public device_t,
- public device_sound_interface
+ public device_sound_interface
{
public:
qsound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
diff --git a/src/emu/sound/spu.c b/src/emu/sound/spu.c
index c0db5b0c5bc..f7cfa4d0a2e 100644
--- a/src/emu/sound/spu.c
+++ b/src/emu/sound/spu.c
@@ -986,7 +986,7 @@ void spu_device::device_start()
memset(cache,0,(spu_ram_size>>4)*sizeof(sample_cache *));
// register save state stuff
- save_item(NAME(reg)); // this covers all spureg.* plus the reverb parameter block
+ save_item(NAME(reg)); // this covers all spureg.* plus the reverb parameter block
save_item(NAME(xa_cnt));
save_item(NAME(cdda_cnt));
save_item(NAME(xa_freq));
diff --git a/src/emu/sound/tms5110.h b/src/emu/sound/tms5110.h
index da3d533c795..d06578e6763 100644
--- a/src/emu/sound/tms5110.h
+++ b/src/emu/sound/tms5110.h
@@ -99,7 +99,7 @@ private:
UINT8 m_PDC;
UINT8 m_CTL_pins;
UINT8 m_speaking_now;
-protected: UINT8 m_talk_status; private:
+protected: UINT8 m_talk_status; private:
UINT8 m_state;
/* Rom interface */
diff --git a/src/emu/video/315_5124.c b/src/emu/video/315_5124.c
index 9792024181c..d0db9c292df 100644
--- a/src/emu/video/315_5124.c
+++ b/src/emu/video/315_5124.c
@@ -1690,11 +1690,11 @@ void sega315_5124_device::vdp_postload()
case 192:
m_frame_timing = (m_is_pal) ? pal_192 : ntsc_192;
break;
-
+
case 224:
m_frame_timing = (m_is_pal) ? pal_224 : ntsc_224;
break;
-
+
case 240:
m_frame_timing = (m_is_pal) ? pal_240 : ntsc_240;
break;
diff --git a/src/emu/video/pc_vga.c b/src/emu/video/pc_vga.c
index 8ff0cae6f9e..871829639e6 100644
--- a/src/emu/video/pc_vga.c
+++ b/src/emu/video/pc_vga.c
@@ -322,7 +322,7 @@ void mach8_device::device_start()
UINT16 vga_device::offset()
{
-// popmessage("Offset: %04x %s %s **",vga.crtc.offset,vga.crtc.dw?"DW":"--",vga.crtc.word_mode?"BYTE":"WORD");
+// popmessage("Offset: %04x %s %s **",vga.crtc.offset,vga.crtc.dw?"DW":"--",vga.crtc.word_mode?"BYTE":"WORD");
if(vga.crtc.dw)
return vga.crtc.offset << 3;
if(vga.crtc.word_mode)
@@ -603,18 +603,18 @@ void svga_device::svga_vh_rgb8(bitmap_rgb32 &bitmap, const rectangle &cliprect)
int yi;
int xi;
UINT8 start_shift;
-// UINT16 line_length;
+// UINT16 line_length;
/* line compare is screen sensitive */
mask_comp = 0x3ff;
curr_addr = 0;
-// if(vga.crtc.dw)
-// line_length = vga.crtc.offset << 3; // doubleword mode
-// else
-// {
-// line_length = vga.crtc.offset << 4;
-// }
+// if(vga.crtc.dw)
+// line_length = vga.crtc.offset << 3; // doubleword mode
+// else
+// {
+// line_length = vga.crtc.offset << 4;
+// }
start_shift = (!(vga.sequencer.data[4] & 0x08)) ? 2 : 0;
diff --git a/src/lib/lua/lapi.c b/src/lib/lua/lapi.c
index 791d85454fb..ece9279144e 100644
--- a/src/lib/lua/lapi.c
+++ b/src/lib/lua/lapi.c
@@ -30,21 +30,21 @@
const char lua_ident[] =
- "$LuaVersion: " LUA_COPYRIGHT " $"
- "$LuaAuthors: " LUA_AUTHORS " $";
+ "$LuaVersion: " LUA_COPYRIGHT " $"
+ "$LuaAuthors: " LUA_AUTHORS " $";
/* value at a non-valid index */
-#define NONVALIDVALUE cast(TValue *, luaO_nilobject)
+#define NONVALIDVALUE cast(TValue *, luaO_nilobject)
/* corresponding test */
-#define isvalid(o) ((o) != luaO_nilobject)
+#define isvalid(o) ((o) != luaO_nilobject)
/* test for pseudo index */
-#define ispseudo(i) ((i) <= LUA_REGISTRYINDEX)
+#define ispseudo(i) ((i) <= LUA_REGISTRYINDEX)
/* test for valid but not pseudo index */
-#define isstackindex(i, o) (isvalid(o) && !ispseudo(i))
+#define isstackindex(i, o) (isvalid(o) && !ispseudo(i))
#define api_checkvalidindex(L, o) api_check(L, isvalid(o), "invalid index")
@@ -53,29 +53,29 @@ const char lua_ident[] =
static TValue *index2addr (lua_State *L, int idx) {
- CallInfo *ci = L->ci;
- if (idx > 0) {
- TValue *o = ci->func + idx;
- api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index");
- if (o >= L->top) return NONVALIDVALUE;
- else return o;
- }
- else if (!ispseudo(idx)) { /* negative index */
- api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
- return L->top + idx;
- }
- else if (idx == LUA_REGISTRYINDEX)
- return &G(L)->l_registry;
- else { /* upvalues */
- idx = LUA_REGISTRYINDEX - idx;
- api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
- if (ttislcf(ci->func)) /* light C function? */
- return NONVALIDVALUE; /* it has no upvalues */
- else {
- CClosure *func = clCvalue(ci->func);
- return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;
- }
- }
+ CallInfo *ci = L->ci;
+ if (idx > 0) {
+ TValue *o = ci->func + idx;
+ api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index");
+ if (o >= L->top) return NONVALIDVALUE;
+ else return o;
+ }
+ else if (!ispseudo(idx)) { /* negative index */
+ api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
+ return L->top + idx;
+ }
+ else if (idx == LUA_REGISTRYINDEX)
+ return &G(L)->l_registry;
+ else { /* upvalues */
+ idx = LUA_REGISTRYINDEX - idx;
+ api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
+ if (ttislcf(ci->func)) /* light C function? */
+ return NONVALIDVALUE; /* it has no upvalues */
+ else {
+ CClosure *func = clCvalue(ci->func);
+ return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;
+ }
+ }
}
@@ -84,60 +84,60 @@ static TValue *index2addr (lua_State *L, int idx) {
** capturing memory errors
*/
static void growstack (lua_State *L, void *ud) {
- int size = *(int *)ud;
- luaD_growstack(L, size);
+ int size = *(int *)ud;
+ luaD_growstack(L, size);
}
LUA_API int lua_checkstack (lua_State *L, int size) {
- int res;
- CallInfo *ci = L->ci;
- lua_lock(L);
- if (L->stack_last - L->top > size) /* stack large enough? */
- res = 1; /* yes; check is OK */
- else { /* no; need to grow stack */
- int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
- if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */
- res = 0; /* no */
- else /* try to grow stack */
- res = (luaD_rawrunprotected(L, &growstack, &size) == LUA_OK);
- }
- if (res && ci->top < L->top + size)
- ci->top = L->top + size; /* adjust frame top */
- lua_unlock(L);
- return res;
+ int res;
+ CallInfo *ci = L->ci;
+ lua_lock(L);
+ if (L->stack_last - L->top > size) /* stack large enough? */
+ res = 1; /* yes; check is OK */
+ else { /* no; need to grow stack */
+ int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
+ if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */
+ res = 0; /* no */
+ else /* try to grow stack */
+ res = (luaD_rawrunprotected(L, &growstack, &size) == LUA_OK);
+ }
+ if (res && ci->top < L->top + size)
+ ci->top = L->top + size; /* adjust frame top */
+ lua_unlock(L);
+ return res;
}
LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
- int i;
- if (from == to) return;
- lua_lock(to);
- api_checknelems(from, n);
- api_check(from, G(from) == G(to), "moving among independent states");
- api_check(from, to->ci->top - to->top >= n, "not enough elements to move");
- from->top -= n;
- for (i = 0; i < n; i++) {
- setobj2s(to, to->top++, from->top + i);
- }
- lua_unlock(to);
+ int i;
+ if (from == to) return;
+ lua_lock(to);
+ api_checknelems(from, n);
+ api_check(from, G(from) == G(to), "moving among independent states");
+ api_check(from, to->ci->top - to->top >= n, "not enough elements to move");
+ from->top -= n;
+ for (i = 0; i < n; i++) {
+ setobj2s(to, to->top++, from->top + i);
+ }
+ lua_unlock(to);
}
LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
- lua_CFunction old;
- lua_lock(L);
- old = G(L)->panic;
- G(L)->panic = panicf;
- lua_unlock(L);
- return old;
+ lua_CFunction old;
+ lua_lock(L);
+ old = G(L)->panic;
+ G(L)->panic = panicf;
+ lua_unlock(L);
+ return old;
}
LUA_API const lua_Number *lua_version (lua_State *L) {
- static const lua_Number version = LUA_VERSION_NUM;
- if (L == NULL) return &version;
- else return G(L)->version;
+ static const lua_Number version = LUA_VERSION_NUM;
+ if (L == NULL) return &version;
+ else return G(L)->version;
}
@@ -151,92 +151,92 @@ LUA_API const lua_Number *lua_version (lua_State *L) {
** convert an acceptable stack index into an absolute index
*/
LUA_API int lua_absindex (lua_State *L, int idx) {
- return (idx > 0 || ispseudo(idx))
- ? idx
- : cast_int(L->top - L->ci->func + idx);
+ return (idx > 0 || ispseudo(idx))
+ ? idx
+ : cast_int(L->top - L->ci->func + idx);
}
LUA_API int lua_gettop (lua_State *L) {
- return cast_int(L->top - (L->ci->func + 1));
+ return cast_int(L->top - (L->ci->func + 1));
}
LUA_API void lua_settop (lua_State *L, int idx) {
- StkId func = L->ci->func;
- lua_lock(L);
- if (idx >= 0) {
- api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
- while (L->top < (func + 1) + idx)
- setnilvalue(L->top++);
- L->top = (func + 1) + idx;
- }
- else {
- api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
- L->top += idx+1; /* `subtract' index (index is negative) */
- }
- lua_unlock(L);
+ StkId func = L->ci->func;
+ lua_lock(L);
+ if (idx >= 0) {
+ api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
+ while (L->top < (func + 1) + idx)
+ setnilvalue(L->top++);
+ L->top = (func + 1) + idx;
+ }
+ else {
+ api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
+ L->top += idx+1; /* `subtract' index (index is negative) */
+ }
+ lua_unlock(L);
}
LUA_API void lua_remove (lua_State *L, int idx) {
- StkId p;
- lua_lock(L);
- p = index2addr(L, idx);
- api_checkstackindex(L, idx, p);
- while (++p < L->top) setobjs2s(L, p-1, p);
- L->top--;
- lua_unlock(L);
+ StkId p;
+ lua_lock(L);
+ p = index2addr(L, idx);
+ api_checkstackindex(L, idx, p);
+ while (++p < L->top) setobjs2s(L, p-1, p);
+ L->top--;
+ lua_unlock(L);
}
LUA_API void lua_insert (lua_State *L, int idx) {
- StkId p;
- StkId q;
- lua_lock(L);
- p = index2addr(L, idx);
- api_checkstackindex(L, idx, p);
- for (q = L->top; q > p; q--) /* use L->top as a temporary */
- setobjs2s(L, q, q - 1);
- setobjs2s(L, p, L->top);
- lua_unlock(L);
+ StkId p;
+ StkId q;
+ lua_lock(L);
+ p = index2addr(L, idx);
+ api_checkstackindex(L, idx, p);
+ for (q = L->top; q > p; q--) /* use L->top as a temporary */
+ setobjs2s(L, q, q - 1);
+ setobjs2s(L, p, L->top);
+ lua_unlock(L);
}
static void moveto (lua_State *L, TValue *fr, int idx) {
- TValue *to = index2addr(L, idx);
- api_checkvalidindex(L, to);
- setobj(L, to, fr);
- if (idx < LUA_REGISTRYINDEX) /* function upvalue? */
- luaC_barrier(L, clCvalue(L->ci->func), fr);
- /* LUA_REGISTRYINDEX does not need gc barrier
- (collector revisits it before finishing collection) */
+ TValue *to = index2addr(L, idx);
+ api_checkvalidindex(L, to);
+ setobj(L, to, fr);
+ if (idx < LUA_REGISTRYINDEX) /* function upvalue? */
+ luaC_barrier(L, clCvalue(L->ci->func), fr);
+ /* LUA_REGISTRYINDEX does not need gc barrier
+ (collector revisits it before finishing collection) */
}
LUA_API void lua_replace (lua_State *L, int idx) {
- lua_lock(L);
- api_checknelems(L, 1);
- moveto(L, L->top - 1, idx);
- L->top--;
- lua_unlock(L);
+ lua_lock(L);
+ api_checknelems(L, 1);
+ moveto(L, L->top - 1, idx);
+ L->top--;
+ lua_unlock(L);
}
LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
- TValue *fr;
- lua_lock(L);
- fr = index2addr(L, fromidx);
- moveto(L, fr, toidx);
- lua_unlock(L);
+ TValue *fr;
+ lua_lock(L);
+ fr = index2addr(L, fromidx);
+ moveto(L, fr, toidx);
+ lua_unlock(L);
}
LUA_API void lua_pushvalue (lua_State *L, int idx) {
- lua_lock(L);
- setobj2s(L, L->top, index2addr(L, idx));
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ setobj2s(L, L->top, index2addr(L, idx));
+ api_incr_top(L);
+ lua_unlock(L);
}
@@ -247,212 +247,212 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) {
LUA_API int lua_type (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- return (isvalid(o) ? ttypenv(o) : LUA_TNONE);
+ StkId o = index2addr(L, idx);
+ return (isvalid(o) ? ttypenv(o) : LUA_TNONE);
}
LUA_API const char *lua_typename (lua_State *L, int t) {
- UNUSED(L);
- return ttypename(t);
+ UNUSED(L);
+ return ttypename(t);
}
LUA_API int lua_iscfunction (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- return (ttislcf(o) || (ttisCclosure(o)));
+ StkId o = index2addr(L, idx);
+ return (ttislcf(o) || (ttisCclosure(o)));
}
LUA_API int lua_isnumber (lua_State *L, int idx) {
- TValue n;
- const TValue *o = index2addr(L, idx);
- return tonumber(o, &n);
+ TValue n;
+ const TValue *o = index2addr(L, idx);
+ return tonumber(o, &n);
}
LUA_API int lua_isstring (lua_State *L, int idx) {
- int t = lua_type(L, idx);
- return (t == LUA_TSTRING || t == LUA_TNUMBER);
+ int t = lua_type(L, idx);
+ return (t == LUA_TSTRING || t == LUA_TNUMBER);
}
LUA_API int lua_isuserdata (lua_State *L, int idx) {
- const TValue *o = index2addr(L, idx);
- return (ttisuserdata(o) || ttislightuserdata(o));
+ const TValue *o = index2addr(L, idx);
+ return (ttisuserdata(o) || ttislightuserdata(o));
}
LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
- StkId o1 = index2addr(L, index1);
- StkId o2 = index2addr(L, index2);
- return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;
+ StkId o1 = index2addr(L, index1);
+ StkId o2 = index2addr(L, index2);
+ return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;
}
LUA_API void lua_arith (lua_State *L, int op) {
- StkId o1; /* 1st operand */
- StkId o2; /* 2nd operand */
- lua_lock(L);
- if (op != LUA_OPUNM) /* all other operations expect two operands */
- api_checknelems(L, 2);
- else { /* for unary minus, add fake 2nd operand */
- api_checknelems(L, 1);
- setobjs2s(L, L->top, L->top - 1);
- L->top++;
- }
- o1 = L->top - 2;
- o2 = L->top - 1;
- if (ttisnumber(o1) && ttisnumber(o2)) {
- setnvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
- }
- else
- luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
- L->top--;
- lua_unlock(L);
+ StkId o1; /* 1st operand */
+ StkId o2; /* 2nd operand */
+ lua_lock(L);
+ if (op != LUA_OPUNM) /* all other operations expect two operands */
+ api_checknelems(L, 2);
+ else { /* for unary minus, add fake 2nd operand */
+ api_checknelems(L, 1);
+ setobjs2s(L, L->top, L->top - 1);
+ L->top++;
+ }
+ o1 = L->top - 2;
+ o2 = L->top - 1;
+ if (ttisnumber(o1) && ttisnumber(o2)) {
+ setnvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
+ }
+ else
+ luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
+ L->top--;
+ lua_unlock(L);
}
LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
- StkId o1, o2;
- int i = 0;
- lua_lock(L); /* may call tag method */
- o1 = index2addr(L, index1);
- o2 = index2addr(L, index2);
- if (isvalid(o1) && isvalid(o2)) {
- switch (op) {
- case LUA_OPEQ: i = equalobj(L, o1, o2); break;
- case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
- case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
- default: api_check(L, 0, "invalid option");
- }
- }
- lua_unlock(L);
- return i;
+ StkId o1, o2;
+ int i = 0;
+ lua_lock(L); /* may call tag method */
+ o1 = index2addr(L, index1);
+ o2 = index2addr(L, index2);
+ if (isvalid(o1) && isvalid(o2)) {
+ switch (op) {
+ case LUA_OPEQ: i = equalobj(L, o1, o2); break;
+ case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
+ case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
+ default: api_check(L, 0, "invalid option");
+ }
+ }
+ lua_unlock(L);
+ return i;
}
LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum) {
- TValue n;
- const TValue *o = index2addr(L, idx);
- if (tonumber(o, &n)) {
- if (isnum) *isnum = 1;
- return nvalue(o);
- }
- else {
- if (isnum) *isnum = 0;
- return 0;
- }
+ TValue n;
+ const TValue *o = index2addr(L, idx);
+ if (tonumber(o, &n)) {
+ if (isnum) *isnum = 1;
+ return nvalue(o);
+ }
+ else {
+ if (isnum) *isnum = 0;
+ return 0;
+ }
}
LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) {
- TValue n;
- const TValue *o = index2addr(L, idx);
- if (tonumber(o, &n)) {
- lua_Integer res;
- lua_Number num = nvalue(o);
- lua_number2integer(res, num);
- if (isnum) *isnum = 1;
- return res;
- }
- else {
- if (isnum) *isnum = 0;
- return 0;
- }
+ TValue n;
+ const TValue *o = index2addr(L, idx);
+ if (tonumber(o, &n)) {
+ lua_Integer res;
+ lua_Number num = nvalue(o);
+ lua_number2integer(res, num);
+ if (isnum) *isnum = 1;
+ return res;
+ }
+ else {
+ if (isnum) *isnum = 0;
+ return 0;
+ }
}
LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) {
- TValue n;
- const TValue *o = index2addr(L, idx);
- if (tonumber(o, &n)) {
- lua_Unsigned res;
- lua_Number num = nvalue(o);
- lua_number2unsigned(res, num);
- if (isnum) *isnum = 1;
- return res;
- }
- else {
- if (isnum) *isnum = 0;
- return 0;
- }
+ TValue n;
+ const TValue *o = index2addr(L, idx);
+ if (tonumber(o, &n)) {
+ lua_Unsigned res;
+ lua_Number num = nvalue(o);
+ lua_number2unsigned(res, num);
+ if (isnum) *isnum = 1;
+ return res;
+ }
+ else {
+ if (isnum) *isnum = 0;
+ return 0;
+ }
}
LUA_API int lua_toboolean (lua_State *L, int idx) {
- const TValue *o = index2addr(L, idx);
- return !l_isfalse(o);
+ const TValue *o = index2addr(L, idx);
+ return !l_isfalse(o);
}
LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
- StkId o = index2addr(L, idx);
- if (!ttisstring(o)) {
- lua_lock(L); /* `luaV_tostring' may create a new string */
- if (!luaV_tostring(L, o)) { /* conversion failed? */
- if (len != NULL) *len = 0;
- lua_unlock(L);
- return NULL;
- }
- luaC_checkGC(L);
- o = index2addr(L, idx); /* previous call may reallocate the stack */
- lua_unlock(L);
- }
- if (len != NULL) *len = tsvalue(o)->len;
- return svalue(o);
+ StkId o = index2addr(L, idx);
+ if (!ttisstring(o)) {
+ lua_lock(L); /* `luaV_tostring' may create a new string */
+ if (!luaV_tostring(L, o)) { /* conversion failed? */
+ if (len != NULL) *len = 0;
+ lua_unlock(L);
+ return NULL;
+ }
+ luaC_checkGC(L);
+ o = index2addr(L, idx); /* previous call may reallocate the stack */
+ lua_unlock(L);
+ }
+ if (len != NULL) *len = tsvalue(o)->len;
+ return svalue(o);
}
LUA_API size_t lua_rawlen (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- switch (ttypenv(o)) {
- case LUA_TSTRING: return tsvalue(o)->len;
- case LUA_TUSERDATA: return uvalue(o)->len;
- case LUA_TTABLE: return luaH_getn(hvalue(o));
- default: return 0;
- }
+ StkId o = index2addr(L, idx);
+ switch (ttypenv(o)) {
+ case LUA_TSTRING: return tsvalue(o)->len;
+ case LUA_TUSERDATA: return uvalue(o)->len;
+ case LUA_TTABLE: return luaH_getn(hvalue(o));
+ default: return 0;
+ }
}
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- if (ttislcf(o)) return fvalue(o);
- else if (ttisCclosure(o))
- return clCvalue(o)->f;
- else return NULL; /* not a C function */
+ StkId o = index2addr(L, idx);
+ if (ttislcf(o)) return fvalue(o);
+ else if (ttisCclosure(o))
+ return clCvalue(o)->f;
+ else return NULL; /* not a C function */
}
LUA_API void *lua_touserdata (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- switch (ttypenv(o)) {
- case LUA_TUSERDATA: return (rawuvalue(o) + 1);
- case LUA_TLIGHTUSERDATA: return pvalue(o);
- default: return NULL;
- }
+ StkId o = index2addr(L, idx);
+ switch (ttypenv(o)) {
+ case LUA_TUSERDATA: return (rawuvalue(o) + 1);
+ case LUA_TLIGHTUSERDATA: return pvalue(o);
+ default: return NULL;
+ }
}
LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- return (!ttisthread(o)) ? NULL : thvalue(o);
+ StkId o = index2addr(L, idx);
+ return (!ttisthread(o)) ? NULL : thvalue(o);
}
LUA_API const void *lua_topointer (lua_State *L, int idx) {
- StkId o = index2addr(L, idx);
- switch (ttype(o)) {
- case LUA_TTABLE: return hvalue(o);
- case LUA_TLCL: return clLvalue(o);
- case LUA_TCCL: return clCvalue(o);
- case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
- case LUA_TTHREAD: return thvalue(o);
- case LUA_TUSERDATA:
- case LUA_TLIGHTUSERDATA:
- return lua_touserdata(L, idx);
- default: return NULL;
- }
+ StkId o = index2addr(L, idx);
+ switch (ttype(o)) {
+ case LUA_TTABLE: return hvalue(o);
+ case LUA_TLCL: return clLvalue(o);
+ case LUA_TCCL: return clCvalue(o);
+ case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
+ case LUA_TTHREAD: return thvalue(o);
+ case LUA_TUSERDATA:
+ case LUA_TLIGHTUSERDATA:
+ return lua_touserdata(L, idx);
+ default: return NULL;
+ }
}
@@ -463,139 +463,139 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
LUA_API void lua_pushnil (lua_State *L) {
- lua_lock(L);
- setnilvalue(L->top);
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ setnilvalue(L->top);
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
- lua_lock(L);
- setnvalue(L->top, n);
- luai_checknum(L, L->top,
- luaG_runerror(L, "C API - attempt to push a signaling NaN"));
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ setnvalue(L->top, n);
+ luai_checknum(L, L->top,
+ luaG_runerror(L, "C API - attempt to push a signaling NaN"));
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
- lua_lock(L);
- setnvalue(L->top, cast_num(n));
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ setnvalue(L->top, cast_num(n));
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
- lua_Number n;
- lua_lock(L);
- n = lua_unsigned2number(u);
- setnvalue(L->top, n);
- api_incr_top(L);
- lua_unlock(L);
+ lua_Number n;
+ lua_lock(L);
+ n = lua_unsigned2number(u);
+ setnvalue(L->top, n);
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
- TString *ts;
- lua_lock(L);
- luaC_checkGC(L);
- ts = luaS_newlstr(L, s, len);
- setsvalue2s(L, L->top, ts);
- api_incr_top(L);
- lua_unlock(L);
- return getstr(ts);
+ TString *ts;
+ lua_lock(L);
+ luaC_checkGC(L);
+ ts = luaS_newlstr(L, s, len);
+ setsvalue2s(L, L->top, ts);
+ api_incr_top(L);
+ lua_unlock(L);
+ return getstr(ts);
}
LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
- if (s == NULL) {
- lua_pushnil(L);
- return NULL;
- }
- else {
- TString *ts;
- lua_lock(L);
- luaC_checkGC(L);
- ts = luaS_new(L, s);
- setsvalue2s(L, L->top, ts);
- api_incr_top(L);
- lua_unlock(L);
- return getstr(ts);
- }
+ if (s == NULL) {
+ lua_pushnil(L);
+ return NULL;
+ }
+ else {
+ TString *ts;
+ lua_lock(L);
+ luaC_checkGC(L);
+ ts = luaS_new(L, s);
+ setsvalue2s(L, L->top, ts);
+ api_incr_top(L);
+ lua_unlock(L);
+ return getstr(ts);
+ }
}
LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
- va_list argp) {
- const char *ret;
- lua_lock(L);
- luaC_checkGC(L);
- ret = luaO_pushvfstring(L, fmt, argp);
- lua_unlock(L);
- return ret;
+ va_list argp) {
+ const char *ret;
+ lua_lock(L);
+ luaC_checkGC(L);
+ ret = luaO_pushvfstring(L, fmt, argp);
+ lua_unlock(L);
+ return ret;
}
LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
- const char *ret;
- va_list argp;
- lua_lock(L);
- luaC_checkGC(L);
- va_start(argp, fmt);
- ret = luaO_pushvfstring(L, fmt, argp);
- va_end(argp);
- lua_unlock(L);
- return ret;
+ const char *ret;
+ va_list argp;
+ lua_lock(L);
+ luaC_checkGC(L);
+ va_start(argp, fmt);
+ ret = luaO_pushvfstring(L, fmt, argp);
+ va_end(argp);
+ lua_unlock(L);
+ return ret;
}
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
- lua_lock(L);
- if (n == 0) {
- setfvalue(L->top, fn);
- }
- else {
- Closure *cl;
- api_checknelems(L, n);
- api_check(L, n <= MAXUPVAL, "upvalue index too large");
- luaC_checkGC(L);
- cl = luaF_newCclosure(L, n);
- cl->c.f = fn;
- L->top -= n;
- while (n--)
- setobj2n(L, &cl->c.upvalue[n], L->top + n);
- setclCvalue(L, L->top, cl);
- }
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ if (n == 0) {
+ setfvalue(L->top, fn);
+ }
+ else {
+ Closure *cl;
+ api_checknelems(L, n);
+ api_check(L, n <= MAXUPVAL, "upvalue index too large");
+ luaC_checkGC(L);
+ cl = luaF_newCclosure(L, n);
+ cl->c.f = fn;
+ L->top -= n;
+ while (n--)
+ setobj2n(L, &cl->c.upvalue[n], L->top + n);
+ setclCvalue(L, L->top, cl);
+ }
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_pushboolean (lua_State *L, int b) {
- lua_lock(L);
- setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
- lua_lock(L);
- setpvalue(L->top, p);
- api_incr_top(L);
- lua_unlock(L);
+ lua_lock(L);
+ setpvalue(L->top, p);
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API int lua_pushthread (lua_State *L) {
- lua_lock(L);
- setthvalue(L, L->top, L);
- api_incr_top(L);
- lua_unlock(L);
- return (G(L)->mainthread == L);
+ lua_lock(L);
+ setthvalue(L, L->top, L);
+ api_incr_top(L);
+ lua_unlock(L);
+ return (G(L)->mainthread == L);
}
@@ -606,123 +606,123 @@ LUA_API int lua_pushthread (lua_State *L) {
LUA_API void lua_getglobal (lua_State *L, const char *var) {
- Table *reg = hvalue(&G(L)->l_registry);
- const TValue *gt; /* global table */
- lua_lock(L);
- gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
- setsvalue2s(L, L->top++, luaS_new(L, var));
- luaV_gettable(L, gt, L->top - 1, L->top - 1);
- lua_unlock(L);
+ Table *reg = hvalue(&G(L)->l_registry);
+ const TValue *gt; /* global table */
+ lua_lock(L);
+ gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
+ setsvalue2s(L, L->top++, luaS_new(L, var));
+ luaV_gettable(L, gt, L->top - 1, L->top - 1);
+ lua_unlock(L);
}
LUA_API void lua_gettable (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- t = index2addr(L, idx);
- luaV_gettable(L, t, L->top - 1, L->top - 1);
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ luaV_gettable(L, t, L->top - 1, L->top - 1);
+ lua_unlock(L);
}
LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
- StkId t;
- lua_lock(L);
- t = index2addr(L, idx);
- setsvalue2s(L, L->top, luaS_new(L, k));
- api_incr_top(L);
- luaV_gettable(L, t, L->top - 1, L->top - 1);
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ setsvalue2s(L, L->top, luaS_new(L, k));
+ api_incr_top(L);
+ luaV_gettable(L, t, L->top - 1, L->top - 1);
+ lua_unlock(L);
}
LUA_API void lua_rawget (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
+ lua_unlock(L);
}
LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
- StkId t;
- lua_lock(L);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- setobj2s(L, L->top, luaH_getint(hvalue(t), n));
- api_incr_top(L);
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ setobj2s(L, L->top, luaH_getint(hvalue(t), n));
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_rawgetp (lua_State *L, int idx, const void *p) {
- StkId t;
- TValue k;
- lua_lock(L);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- setpvalue(&k, cast(void *, p));
- setobj2s(L, L->top, luaH_get(hvalue(t), &k));
- api_incr_top(L);
- lua_unlock(L);
+ StkId t;
+ TValue k;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ setpvalue(&k, cast(void *, p));
+ setobj2s(L, L->top, luaH_get(hvalue(t), &k));
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
- Table *t;
- lua_lock(L);
- luaC_checkGC(L);
- t = luaH_new(L);
- sethvalue(L, L->top, t);
- api_incr_top(L);
- if (narray > 0 || nrec > 0)
- luaH_resize(L, t, narray, nrec);
- lua_unlock(L);
+ Table *t;
+ lua_lock(L);
+ luaC_checkGC(L);
+ t = luaH_new(L);
+ sethvalue(L, L->top, t);
+ api_incr_top(L);
+ if (narray > 0 || nrec > 0)
+ luaH_resize(L, t, narray, nrec);
+ lua_unlock(L);
}
LUA_API int lua_getmetatable (lua_State *L, int objindex) {
- const TValue *obj;
- Table *mt = NULL;
- int res;
- lua_lock(L);
- obj = index2addr(L, objindex);
- switch (ttypenv(obj)) {
- case LUA_TTABLE:
- mt = hvalue(obj)->metatable;
- break;
- case LUA_TUSERDATA:
- mt = uvalue(obj)->metatable;
- break;
- default:
- mt = G(L)->mt[ttypenv(obj)];
- break;
- }
- if (mt == NULL)
- res = 0;
- else {
- sethvalue(L, L->top, mt);
- api_incr_top(L);
- res = 1;
- }
- lua_unlock(L);
- return res;
+ const TValue *obj;
+ Table *mt = NULL;
+ int res;
+ lua_lock(L);
+ obj = index2addr(L, objindex);
+ switch (ttypenv(obj)) {
+ case LUA_TTABLE:
+ mt = hvalue(obj)->metatable;
+ break;
+ case LUA_TUSERDATA:
+ mt = uvalue(obj)->metatable;
+ break;
+ default:
+ mt = G(L)->mt[ttypenv(obj)];
+ break;
+ }
+ if (mt == NULL)
+ res = 0;
+ else {
+ sethvalue(L, L->top, mt);
+ api_incr_top(L);
+ res = 1;
+ }
+ lua_unlock(L);
+ return res;
}
LUA_API void lua_getuservalue (lua_State *L, int idx) {
- StkId o;
- lua_lock(L);
- o = index2addr(L, idx);
- api_check(L, ttisuserdata(o), "userdata expected");
- if (uvalue(o)->env) {
- sethvalue(L, L->top, uvalue(o)->env);
- } else
- setnilvalue(L->top);
- api_incr_top(L);
- lua_unlock(L);
+ StkId o;
+ lua_lock(L);
+ o = index2addr(L, idx);
+ api_check(L, ttisuserdata(o), "userdata expected");
+ if (uvalue(o)->env) {
+ sethvalue(L, L->top, uvalue(o)->env);
+ } else
+ setnilvalue(L->top);
+ api_incr_top(L);
+ lua_unlock(L);
}
@@ -732,138 +732,138 @@ LUA_API void lua_getuservalue (lua_State *L, int idx) {
LUA_API void lua_setglobal (lua_State *L, const char *var) {
- Table *reg = hvalue(&G(L)->l_registry);
- const TValue *gt; /* global table */
- lua_lock(L);
- api_checknelems(L, 1);
- gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
- setsvalue2s(L, L->top++, luaS_new(L, var));
- luaV_settable(L, gt, L->top - 1, L->top - 2);
- L->top -= 2; /* pop value and key */
- lua_unlock(L);
+ Table *reg = hvalue(&G(L)->l_registry);
+ const TValue *gt; /* global table */
+ lua_lock(L);
+ api_checknelems(L, 1);
+ gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
+ setsvalue2s(L, L->top++, luaS_new(L, var));
+ luaV_settable(L, gt, L->top - 1, L->top - 2);
+ L->top -= 2; /* pop value and key */
+ lua_unlock(L);
}
LUA_API void lua_settable (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- api_checknelems(L, 2);
- t = index2addr(L, idx);
- luaV_settable(L, t, L->top - 2, L->top - 1);
- L->top -= 2; /* pop index and value */
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ api_checknelems(L, 2);
+ t = index2addr(L, idx);
+ luaV_settable(L, t, L->top - 2, L->top - 1);
+ L->top -= 2; /* pop index and value */
+ lua_unlock(L);
}
LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
- StkId t;
- lua_lock(L);
- api_checknelems(L, 1);
- t = index2addr(L, idx);
- setsvalue2s(L, L->top++, luaS_new(L, k));
- luaV_settable(L, t, L->top - 1, L->top - 2);
- L->top -= 2; /* pop value and key */
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ t = index2addr(L, idx);
+ setsvalue2s(L, L->top++, luaS_new(L, k));
+ luaV_settable(L, t, L->top - 1, L->top - 2);
+ L->top -= 2; /* pop value and key */
+ lua_unlock(L);
}
LUA_API void lua_rawset (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- api_checknelems(L, 2);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
- invalidateTMcache(hvalue(t));
- luaC_barrierback(L, gcvalue(t), L->top-1);
- L->top -= 2;
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ api_checknelems(L, 2);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
+ invalidateTMcache(hvalue(t));
+ luaC_barrierback(L, gcvalue(t), L->top-1);
+ L->top -= 2;
+ lua_unlock(L);
}
LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
- StkId t;
- lua_lock(L);
- api_checknelems(L, 1);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- luaH_setint(L, hvalue(t), n, L->top - 1);
- luaC_barrierback(L, gcvalue(t), L->top-1);
- L->top--;
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ luaH_setint(L, hvalue(t), n, L->top - 1);
+ luaC_barrierback(L, gcvalue(t), L->top-1);
+ L->top--;
+ lua_unlock(L);
}
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
- StkId t;
- TValue k;
- lua_lock(L);
- api_checknelems(L, 1);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- setpvalue(&k, cast(void *, p));
- setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
- luaC_barrierback(L, gcvalue(t), L->top - 1);
- L->top--;
- lua_unlock(L);
+ StkId t;
+ TValue k;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ setpvalue(&k, cast(void *, p));
+ setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
+ luaC_barrierback(L, gcvalue(t), L->top - 1);
+ L->top--;
+ lua_unlock(L);
}
LUA_API int lua_setmetatable (lua_State *L, int objindex) {
- TValue *obj;
- Table *mt;
- lua_lock(L);
- api_checknelems(L, 1);
- obj = index2addr(L, objindex);
- if (ttisnil(L->top - 1))
- mt = NULL;
- else {
- api_check(L, ttistable(L->top - 1), "table expected");
- mt = hvalue(L->top - 1);
- }
- switch (ttypenv(obj)) {
- case LUA_TTABLE: {
- hvalue(obj)->metatable = mt;
- if (mt) {
- luaC_objbarrierback(L, gcvalue(obj), mt);
- luaC_checkfinalizer(L, gcvalue(obj), mt);
- }
- break;
- }
- case LUA_TUSERDATA: {
- uvalue(obj)->metatable = mt;
- if (mt) {
- luaC_objbarrier(L, rawuvalue(obj), mt);
- luaC_checkfinalizer(L, gcvalue(obj), mt);
- }
- break;
- }
- default: {
- G(L)->mt[ttypenv(obj)] = mt;
- break;
- }
- }
- L->top--;
- lua_unlock(L);
- return 1;
+ TValue *obj;
+ Table *mt;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ obj = index2addr(L, objindex);
+ if (ttisnil(L->top - 1))
+ mt = NULL;
+ else {
+ api_check(L, ttistable(L->top - 1), "table expected");
+ mt = hvalue(L->top - 1);
+ }
+ switch (ttypenv(obj)) {
+ case LUA_TTABLE: {
+ hvalue(obj)->metatable = mt;
+ if (mt) {
+ luaC_objbarrierback(L, gcvalue(obj), mt);
+ luaC_checkfinalizer(L, gcvalue(obj), mt);
+ }
+ break;
+ }
+ case LUA_TUSERDATA: {
+ uvalue(obj)->metatable = mt;
+ if (mt) {
+ luaC_objbarrier(L, rawuvalue(obj), mt);
+ luaC_checkfinalizer(L, gcvalue(obj), mt);
+ }
+ break;
+ }
+ default: {
+ G(L)->mt[ttypenv(obj)] = mt;
+ break;
+ }
+ }
+ L->top--;
+ lua_unlock(L);
+ return 1;
}
LUA_API void lua_setuservalue (lua_State *L, int idx) {
- StkId o;
- lua_lock(L);
- api_checknelems(L, 1);
- o = index2addr(L, idx);
- api_check(L, ttisuserdata(o), "userdata expected");
- if (ttisnil(L->top - 1))
- uvalue(o)->env = NULL;
- else {
- api_check(L, ttistable(L->top - 1), "table expected");
- uvalue(o)->env = hvalue(L->top - 1);
- luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
- }
- L->top--;
- lua_unlock(L);
+ StkId o;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ o = index2addr(L, idx);
+ api_check(L, ttisuserdata(o), "userdata expected");
+ if (ttisnil(L->top - 1))
+ uvalue(o)->env = NULL;
+ else {
+ api_check(L, ttistable(L->top - 1), "table expected");
+ uvalue(o)->env = hvalue(L->top - 1);
+ luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
+ }
+ L->top--;
+ lua_unlock(L);
}
@@ -873,38 +873,38 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) {
#define checkresults(L,na,nr) \
- api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
+ api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
"results from function overflow current stack size")
LUA_API int lua_getctx (lua_State *L, int *ctx) {
- if (L->ci->callstatus & CIST_YIELDED) {
- if (ctx) *ctx = L->ci->u.c.ctx;
- return L->ci->u.c.status;
- }
- else return LUA_OK;
+ if (L->ci->callstatus & CIST_YIELDED) {
+ if (ctx) *ctx = L->ci->u.c.ctx;
+ return L->ci->u.c.status;
+ }
+ else return LUA_OK;
}
LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx,
- lua_CFunction k) {
- StkId func;
- lua_lock(L);
- api_check(L, k == NULL || !isLua(L->ci),
- "cannot use continuations inside hooks");
- api_checknelems(L, nargs+1);
- api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
- checkresults(L, nargs, nresults);
- func = L->top - (nargs+1);
- if (k != NULL && L->nny == 0) { /* need to prepare continuation? */
- L->ci->u.c.k = k; /* save continuation */
- L->ci->u.c.ctx = ctx; /* save context */
- luaD_call(L, func, nresults, 1); /* do the call */
- }
- else /* no continuation or no yieldable */
- luaD_call(L, func, nresults, 0); /* just do the call */
- adjustresults(L, nresults);
- lua_unlock(L);
+ lua_CFunction k) {
+ StkId func;
+ lua_lock(L);
+ api_check(L, k == NULL || !isLua(L->ci),
+ "cannot use continuations inside hooks");
+ api_checknelems(L, nargs+1);
+ api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
+ checkresults(L, nargs, nresults);
+ func = L->top - (nargs+1);
+ if (k != NULL && L->nny == 0) { /* need to prepare continuation? */
+ L->ci->u.c.k = k; /* save continuation */
+ L->ci->u.c.ctx = ctx; /* save context */
+ luaD_call(L, func, nresults, 1); /* do the call */
+ }
+ else /* no continuation or no yieldable */
+ luaD_call(L, func, nresults, 0); /* just do the call */
+ adjustresults(L, nresults);
+ lua_unlock(L);
}
@@ -913,104 +913,104 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx,
** Execute a protected call.
*/
struct CallS { /* data to `f_call' */
- StkId func;
- int nresults;
+ StkId func;
+ int nresults;
};
static void f_call (lua_State *L, void *ud) {
- struct CallS *c = cast(struct CallS *, ud);
- luaD_call(L, c->func, c->nresults, 0);
+ struct CallS *c = cast(struct CallS *, ud);
+ luaD_call(L, c->func, c->nresults, 0);
}
LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
- int ctx, lua_CFunction k) {
- struct CallS c;
- int status;
- ptrdiff_t func;
- lua_lock(L);
- api_check(L, k == NULL || !isLua(L->ci),
- "cannot use continuations inside hooks");
- api_checknelems(L, nargs+1);
- api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
- checkresults(L, nargs, nresults);
- if (errfunc == 0)
- func = 0;
- else {
- StkId o = index2addr(L, errfunc);
- api_checkstackindex(L, errfunc, o);
- func = savestack(L, o);
- }
- c.func = L->top - (nargs+1); /* function to be called */
- if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */
- c.nresults = nresults; /* do a 'conventional' protected call */
- status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
- }
- else { /* prepare continuation (call is already protected by 'resume') */
- CallInfo *ci = L->ci;
- ci->u.c.k = k; /* save continuation */
- ci->u.c.ctx = ctx; /* save context */
- /* save information for error recovery */
- ci->extra = savestack(L, c.func);
- ci->u.c.old_allowhook = L->allowhook;
- ci->u.c.old_errfunc = L->errfunc;
- L->errfunc = func;
- /* mark that function may do error recovery */
- ci->callstatus |= CIST_YPCALL;
- luaD_call(L, c.func, nresults, 1); /* do the call */
- ci->callstatus &= ~CIST_YPCALL;
- L->errfunc = ci->u.c.old_errfunc;
- status = LUA_OK; /* if it is here, there were no errors */
- }
- adjustresults(L, nresults);
- lua_unlock(L);
- return status;
+ int ctx, lua_CFunction k) {
+ struct CallS c;
+ int status;
+ ptrdiff_t func;
+ lua_lock(L);
+ api_check(L, k == NULL || !isLua(L->ci),
+ "cannot use continuations inside hooks");
+ api_checknelems(L, nargs+1);
+ api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
+ checkresults(L, nargs, nresults);
+ if (errfunc == 0)
+ func = 0;
+ else {
+ StkId o = index2addr(L, errfunc);
+ api_checkstackindex(L, errfunc, o);
+ func = savestack(L, o);
+ }
+ c.func = L->top - (nargs+1); /* function to be called */
+ if (k == NULL || L->nny > 0) { /* no continuation or no yieldable? */
+ c.nresults = nresults; /* do a 'conventional' protected call */
+ status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
+ }
+ else { /* prepare continuation (call is already protected by 'resume') */
+ CallInfo *ci = L->ci;
+ ci->u.c.k = k; /* save continuation */
+ ci->u.c.ctx = ctx; /* save context */
+ /* save information for error recovery */
+ ci->extra = savestack(L, c.func);
+ ci->u.c.old_allowhook = L->allowhook;
+ ci->u.c.old_errfunc = L->errfunc;
+ L->errfunc = func;
+ /* mark that function may do error recovery */
+ ci->callstatus |= CIST_YPCALL;
+ luaD_call(L, c.func, nresults, 1); /* do the call */
+ ci->callstatus &= ~CIST_YPCALL;
+ L->errfunc = ci->u.c.old_errfunc;
+ status = LUA_OK; /* if it is here, there were no errors */
+ }
+ adjustresults(L, nresults);
+ lua_unlock(L);
+ return status;
}
LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
- const char *chunkname, const char *mode) {
- ZIO z;
- int status;
- lua_lock(L);
- if (!chunkname) chunkname = "?";
- luaZ_init(L, &z, reader, data);
- status = luaD_protectedparser(L, &z, chunkname, mode);
- if (status == LUA_OK) { /* no errors? */
- LClosure *f = clLvalue(L->top - 1); /* get newly created function */
- if (f->nupvalues == 1) { /* does it have one upvalue? */
- /* get global table from registry */
- Table *reg = hvalue(&G(L)->l_registry);
- const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
- /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
- setobj(L, f->upvals[0]->v, gt);
- luaC_barrier(L, f->upvals[0], gt);
- }
- }
- lua_unlock(L);
- return status;
+ const char *chunkname, const char *mode) {
+ ZIO z;
+ int status;
+ lua_lock(L);
+ if (!chunkname) chunkname = "?";
+ luaZ_init(L, &z, reader, data);
+ status = luaD_protectedparser(L, &z, chunkname, mode);
+ if (status == LUA_OK) { /* no errors? */
+ LClosure *f = clLvalue(L->top - 1); /* get newly created function */
+ if (f->nupvalues == 1) { /* does it have one upvalue? */
+ /* get global table from registry */
+ Table *reg = hvalue(&G(L)->l_registry);
+ const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
+ /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
+ setobj(L, f->upvals[0]->v, gt);
+ luaC_barrier(L, f->upvals[0], gt);
+ }
+ }
+ lua_unlock(L);
+ return status;
}
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
- int status;
- TValue *o;
- lua_lock(L);
- api_checknelems(L, 1);
- o = L->top - 1;
- if (isLfunction(o))
- status = luaU_dump(L, getproto(o), writer, data, 0);
- else
- status = 1;
- lua_unlock(L);
- return status;
+ int status;
+ TValue *o;
+ lua_lock(L);
+ api_checknelems(L, 1);
+ o = L->top - 1;
+ if (isLfunction(o))
+ status = luaU_dump(L, getproto(o), writer, data, 0);
+ else
+ status = 1;
+ lua_unlock(L);
+ return status;
}
LUA_API int lua_status (lua_State *L) {
- return L->status;
+ return L->status;
}
@@ -1019,80 +1019,80 @@ LUA_API int lua_status (lua_State *L) {
*/
LUA_API int lua_gc (lua_State *L, int what, int data) {
- int res = 0;
- global_State *g;
- lua_lock(L);
- g = G(L);
- switch (what) {
- case LUA_GCSTOP: {
- g->gcrunning = 0;
- break;
- }
- case LUA_GCRESTART: {
- luaE_setdebt(g, 0);
- g->gcrunning = 1;
- break;
- }
- case LUA_GCCOLLECT: {
- luaC_fullgc(L, 0);
- break;
- }
- case LUA_GCCOUNT: {
- /* GC values are expressed in Kbytes: #bytes/2^10 */
- res = cast_int(gettotalbytes(g) >> 10);
- break;
- }
- case LUA_GCCOUNTB: {
- res = cast_int(gettotalbytes(g) & 0x3ff);
- break;
- }
- case LUA_GCSTEP: {
- if (g->gckind == KGC_GEN) { /* generational mode? */
- res = (g->GCestimate == 0); /* true if it will do major collection */
- luaC_forcestep(L); /* do a single step */
- }
- else {
- lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE;
- if (g->gcrunning)
- debt += g->GCdebt; /* include current debt */
- luaE_setdebt(g, debt);
- luaC_forcestep(L);
- if (g->gcstate == GCSpause) /* end of cycle? */
- res = 1; /* signal it */
- }
- break;
- }
- case LUA_GCSETPAUSE: {
- res = g->gcpause;
- g->gcpause = data;
- break;
- }
- case LUA_GCSETMAJORINC: {
- res = g->gcmajorinc;
- g->gcmajorinc = data;
- break;
- }
- case LUA_GCSETSTEPMUL: {
- res = g->gcstepmul;
- g->gcstepmul = data;
- break;
- }
- case LUA_GCISRUNNING: {
- res = g->gcrunning;
- break;
- }
- case LUA_GCGEN: { /* change collector to generational mode */
- luaC_changemode(L, KGC_GEN);
- break;
- }
- case LUA_GCINC: { /* change collector to incremental mode */
- luaC_changemode(L, KGC_NORMAL);
- break;
- }
- default: res = -1; /* invalid option */
- }
- lua_unlock(L);
- return res;
+ int res = 0;
+ global_State *g;
+ lua_lock(L);
+ g = G(L);
+ switch (what) {
+ case LUA_GCSTOP: {
+ g->gcrunning = 0;
+ break;
+ }
+ case LUA_GCRESTART: {
+ luaE_setdebt(g, 0);
+ g->gcrunning = 1;
+ break;
+ }
+ case LUA_GCCOLLECT: {
+ luaC_fullgc(L, 0);
+ break;
+ }
+ case LUA_GCCOUNT: {
+ /* GC values are expressed in Kbytes: #bytes/2^10 */
+ res = cast_int(gettotalbytes(g) >> 10);
+ break;
+ }
+ case LUA_GCCOUNTB: {
+ res = cast_int(gettotalbytes(g) & 0x3ff);
+ break;
+ }
+ case LUA_GCSTEP: {
+ if (g->gckind == KGC_GEN) { /* generational mode? */
+ res = (g->GCestimate == 0); /* true if it will do major collection */
+ luaC_forcestep(L); /* do a single step */
+ }
+ else {
+ lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE;
+ if (g->gcrunning)
+ debt += g->GCdebt; /* include current debt */
+ luaE_setdebt(g, debt);
+ luaC_forcestep(L);
+ if (g->gcstate == GCSpause) /* end of cycle? */
+ res = 1; /* signal it */
+ }
+ break;
+ }
+ case LUA_GCSETPAUSE: {
+ res = g->gcpause;
+ g->gcpause = data;
+ break;
+ }
+ case LUA_GCSETMAJORINC: {
+ res = g->gcmajorinc;
+ g->gcmajorinc = data;
+ break;
+ }
+ case LUA_GCSETSTEPMUL: {
+ res = g->gcstepmul;
+ g->gcstepmul = data;
+ break;
+ }
+ case LUA_GCISRUNNING: {
+ res = g->gcrunning;
+ break;
+ }
+ case LUA_GCGEN: { /* change collector to generational mode */
+ luaC_changemode(L, KGC_GEN);
+ break;
+ }
+ case LUA_GCINC: { /* change collector to incremental mode */
+ luaC_changemode(L, KGC_NORMAL);
+ break;
+ }
+ default: res = -1; /* invalid option */
+ }
+ lua_unlock(L);
+ return res;
}
@@ -1103,182 +1103,181 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
LUA_API int lua_error (lua_State *L) {
- lua_lock(L);
- api_checknelems(L, 1);
- luaG_errormsg(L);
- /* code unreachable; will unlock when control actually leaves the kernel */
- return 0; /* to avoid warnings */
+ lua_lock(L);
+ api_checknelems(L, 1);
+ luaG_errormsg(L);
+ /* code unreachable; will unlock when control actually leaves the kernel */
+ return 0; /* to avoid warnings */
}
LUA_API int lua_next (lua_State *L, int idx) {
- StkId t;
- int more;
- lua_lock(L);
- t = index2addr(L, idx);
- api_check(L, ttistable(t), "table expected");
- more = luaH_next(L, hvalue(t), L->top - 1);
- if (more) {
- api_incr_top(L);
- }
- else /* no more elements */
- L->top -= 1; /* remove key */
- lua_unlock(L);
- return more;
+ StkId t;
+ int more;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ api_check(L, ttistable(t), "table expected");
+ more = luaH_next(L, hvalue(t), L->top - 1);
+ if (more) {
+ api_incr_top(L);
+ }
+ else /* no more elements */
+ L->top -= 1; /* remove key */
+ lua_unlock(L);
+ return more;
}
LUA_API void lua_concat (lua_State *L, int n) {
- lua_lock(L);
- api_checknelems(L, n);
- if (n >= 2) {
- luaC_checkGC(L);
- luaV_concat(L, n);
- }
- else if (n == 0) { /* push empty string */
- setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
- api_incr_top(L);
- }
- /* else n == 1; nothing to do */
- lua_unlock(L);
+ lua_lock(L);
+ api_checknelems(L, n);
+ if (n >= 2) {
+ luaC_checkGC(L);
+ luaV_concat(L, n);
+ }
+ else if (n == 0) { /* push empty string */
+ setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
+ api_incr_top(L);
+ }
+ /* else n == 1; nothing to do */
+ lua_unlock(L);
}
LUA_API void lua_len (lua_State *L, int idx) {
- StkId t;
- lua_lock(L);
- t = index2addr(L, idx);
- luaV_objlen(L, L->top, t);
- api_incr_top(L);
- lua_unlock(L);
+ StkId t;
+ lua_lock(L);
+ t = index2addr(L, idx);
+ luaV_objlen(L, L->top, t);
+ api_incr_top(L);
+ lua_unlock(L);
}
LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
- lua_Alloc f;
- lua_lock(L);
- if (ud) *ud = G(L)->ud;
- f = G(L)->frealloc;
- lua_unlock(L);
- return f;
+ lua_Alloc f;
+ lua_lock(L);
+ if (ud) *ud = G(L)->ud;
+ f = G(L)->frealloc;
+ lua_unlock(L);
+ return f;
}
LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
- lua_lock(L);
- G(L)->ud = ud;
- G(L)->frealloc = f;
- lua_unlock(L);
+ lua_lock(L);
+ G(L)->ud = ud;
+ G(L)->frealloc = f;
+ lua_unlock(L);
}
LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
- Udata *u;
- lua_lock(L);
- luaC_checkGC(L);
- u = luaS_newudata(L, size, NULL);
- setuvalue(L, L->top, u);
- api_incr_top(L);
- lua_unlock(L);
- return u + 1;
+ Udata *u;
+ lua_lock(L);
+ luaC_checkGC(L);
+ u = luaS_newudata(L, size, NULL);
+ setuvalue(L, L->top, u);
+ api_incr_top(L);
+ lua_unlock(L);
+ return u + 1;
}
static const char *aux_upvalue (StkId fi, int n, TValue **val,
- GCObject **owner) {
- switch (ttype(fi)) {
- case LUA_TCCL: { /* C closure */
- CClosure *f = clCvalue(fi);
- if (!(1 <= n && n <= f->nupvalues)) return NULL;
- *val = &f->upvalue[n-1];
- if (owner) *owner = obj2gco(f);
- return "";
- }
- case LUA_TLCL: { /* Lua closure */
- LClosure *f = clLvalue(fi);
- TString *name;
- Proto *p = f->p;
- if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
- *val = f->upvals[n-1]->v;
- if (owner) *owner = obj2gco(f->upvals[n - 1]);
- name = p->upvalues[n-1].name;
- return (name == NULL) ? "" : getstr(name);
- }
- default: return NULL; /* not a closure */
- }
+ GCObject **owner) {
+ switch (ttype(fi)) {
+ case LUA_TCCL: { /* C closure */
+ CClosure *f = clCvalue(fi);
+ if (!(1 <= n && n <= f->nupvalues)) return NULL;
+ *val = &f->upvalue[n-1];
+ if (owner) *owner = obj2gco(f);
+ return "";
+ }
+ case LUA_TLCL: { /* Lua closure */
+ LClosure *f = clLvalue(fi);
+ TString *name;
+ Proto *p = f->p;
+ if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
+ *val = f->upvals[n-1]->v;
+ if (owner) *owner = obj2gco(f->upvals[n - 1]);
+ name = p->upvalues[n-1].name;
+ return (name == NULL) ? "" : getstr(name);
+ }
+ default: return NULL; /* not a closure */
+ }
}
LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
- const char *name;
- TValue *val = NULL; /* to avoid warnings */
- lua_lock(L);
- name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL);
- if (name) {
- setobj2s(L, L->top, val);
- api_incr_top(L);
- }
- lua_unlock(L);
- return name;
+ const char *name;
+ TValue *val = NULL; /* to avoid warnings */
+ lua_lock(L);
+ name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL);
+ if (name) {
+ setobj2s(L, L->top, val);
+ api_incr_top(L);
+ }
+ lua_unlock(L);
+ return name;
}
LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
- const char *name;
- TValue *val = NULL; /* to avoid warnings */
- GCObject *owner = NULL; /* to avoid warnings */
- StkId fi;
- lua_lock(L);
- fi = index2addr(L, funcindex);
- api_checknelems(L, 1);
- name = aux_upvalue(fi, n, &val, &owner);
- if (name) {
- L->top--;
- setobj(L, val, L->top);
- luaC_barrier(L, owner, L->top);
- }
- lua_unlock(L);
- return name;
+ const char *name;
+ TValue *val = NULL; /* to avoid warnings */
+ GCObject *owner = NULL; /* to avoid warnings */
+ StkId fi;
+ lua_lock(L);
+ fi = index2addr(L, funcindex);
+ api_checknelems(L, 1);
+ name = aux_upvalue(fi, n, &val, &owner);
+ if (name) {
+ L->top--;
+ setobj(L, val, L->top);
+ luaC_barrier(L, owner, L->top);
+ }
+ lua_unlock(L);
+ return name;
}
static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
- LClosure *f;
- StkId fi = index2addr(L, fidx);
- api_check(L, ttisLclosure(fi), "Lua function expected");
- f = clLvalue(fi);
- api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
- if (pf) *pf = f;
- return &f->upvals[n - 1]; /* get its upvalue pointer */
+ LClosure *f;
+ StkId fi = index2addr(L, fidx);
+ api_check(L, ttisLclosure(fi), "Lua function expected");
+ f = clLvalue(fi);
+ api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
+ if (pf) *pf = f;
+ return &f->upvals[n - 1]; /* get its upvalue pointer */
}
LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
- StkId fi = index2addr(L, fidx);
- switch (ttype(fi)) {
- case LUA_TLCL: { /* lua closure */
- return *getupvalref(L, fidx, n, NULL);
- }
- case LUA_TCCL: { /* C closure */
- CClosure *f = clCvalue(fi);
- api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
- return &f->upvalue[n - 1];
- }
- default: {
- api_check(L, 0, "closure expected");
- return NULL;
- }
- }
+ StkId fi = index2addr(L, fidx);
+ switch (ttype(fi)) {
+ case LUA_TLCL: { /* lua closure */
+ return *getupvalref(L, fidx, n, NULL);
+ }
+ case LUA_TCCL: { /* C closure */
+ CClosure *f = clCvalue(fi);
+ api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
+ return &f->upvalue[n - 1];
+ }
+ default: {
+ api_check(L, 0, "closure expected");
+ return NULL;
+ }
+ }
}
LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
- int fidx2, int n2) {
- LClosure *f1;
- UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
- UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
- *up1 = *up2;
- luaC_objbarrier(L, f1, *up2);
+ int fidx2, int n2) {
+ LClosure *f1;
+ UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
+ UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
+ *up1 = *up2;
+ luaC_objbarrier(L, f1, *up2);
}
-
diff --git a/src/lib/lua/lapi.h b/src/lib/lua/lapi.h
index 0909a3911d2..08f54be8d00 100644
--- a/src/lib/lua/lapi.h
+++ b/src/lib/lua/lapi.h
@@ -15,10 +15,10 @@
"stack overflow");}
#define adjustresults(L,nres) \
- { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
+ { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
-#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
- "not enough elements in the stack")
+#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
+ "not enough elements in the stack")
#endif
diff --git a/src/lib/lua/lauxlib.c b/src/lib/lua/lauxlib.c
index 2e989d661b8..61008134dc3 100644
--- a/src/lib/lua/lauxlib.c
+++ b/src/lib/lua/lauxlib.c
@@ -31,8 +31,8 @@
*/
-#define LEVELS1 12 /* size of the first part of the stack */
-#define LEVELS2 10 /* size of the second part of the stack */
+#define LEVELS1 12 /* size of the first part of the stack */
+#define LEVELS2 10 /* size of the second part of the stack */
@@ -41,104 +41,104 @@
** return 1 + string at top if find a good name.
*/
static int findfield (lua_State *L, int objidx, int level) {
- if (level == 0 || !lua_istable(L, -1))
- return 0; /* not found */
- lua_pushnil(L); /* start 'next' loop */
- while (lua_next(L, -2)) { /* for each pair in table */
- if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
- if (lua_rawequal(L, objidx, -1)) { /* found object? */
- lua_pop(L, 1); /* remove value (but keep name) */
- return 1;
- }
- else if (findfield(L, objidx, level - 1)) { /* try recursively */
- lua_remove(L, -2); /* remove table (but keep name) */
- lua_pushliteral(L, ".");
- lua_insert(L, -2); /* place '.' between the two names */
- lua_concat(L, 3);
- return 1;
- }
- }
- lua_pop(L, 1); /* remove value */
- }
- return 0; /* not found */
+ if (level == 0 || !lua_istable(L, -1))
+ return 0; /* not found */
+ lua_pushnil(L); /* start 'next' loop */
+ while (lua_next(L, -2)) { /* for each pair in table */
+ if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
+ if (lua_rawequal(L, objidx, -1)) { /* found object? */
+ lua_pop(L, 1); /* remove value (but keep name) */
+ return 1;
+ }
+ else if (findfield(L, objidx, level - 1)) { /* try recursively */
+ lua_remove(L, -2); /* remove table (but keep name) */
+ lua_pushliteral(L, ".");
+ lua_insert(L, -2); /* place '.' between the two names */
+ lua_concat(L, 3);
+ return 1;
+ }
+ }
+ lua_pop(L, 1); /* remove value */
+ }
+ return 0; /* not found */
}
static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
- int top = lua_gettop(L);
- lua_getinfo(L, "f", ar); /* push function */
- lua_pushglobaltable(L);
- if (findfield(L, top + 1, 2)) {
- lua_copy(L, -1, top + 1); /* move name to proper place */
- lua_pop(L, 2); /* remove pushed values */
- return 1;
- }
- else {
- lua_settop(L, top); /* remove function and global table */
- return 0;
- }
+ int top = lua_gettop(L);
+ lua_getinfo(L, "f", ar); /* push function */
+ lua_pushglobaltable(L);
+ if (findfield(L, top + 1, 2)) {
+ lua_copy(L, -1, top + 1); /* move name to proper place */
+ lua_pop(L, 2); /* remove pushed values */
+ return 1;
+ }
+ else {
+ lua_settop(L, top); /* remove function and global table */
+ return 0;
+ }
}
static void pushfuncname (lua_State *L, lua_Debug *ar) {
- if (*ar->namewhat != '\0') /* is there a name? */
- lua_pushfstring(L, "function " LUA_QS, ar->name);
- else if (*ar->what == 'm') /* main? */
- lua_pushliteral(L, "main chunk");
- else if (*ar->what == 'C') {
- if (pushglobalfuncname(L, ar)) {
- lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
- lua_remove(L, -2); /* remove name */
- }
- else
- lua_pushliteral(L, "?");
- }
- else
- lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
+ if (*ar->namewhat != '\0') /* is there a name? */
+ lua_pushfstring(L, "function " LUA_QS, ar->name);
+ else if (*ar->what == 'm') /* main? */
+ lua_pushliteral(L, "main chunk");
+ else if (*ar->what == 'C') {
+ if (pushglobalfuncname(L, ar)) {
+ lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
+ lua_remove(L, -2); /* remove name */
+ }
+ else
+ lua_pushliteral(L, "?");
+ }
+ else
+ lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
}
static int countlevels (lua_State *L) {
- lua_Debug ar;
- int li = 1, le = 1;
- /* find an upper bound */
- while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
- /* do a binary search */
- while (li < le) {
- int m = (li + le)/2;
- if (lua_getstack(L, m, &ar)) li = m + 1;
- else le = m;
- }
- return le - 1;
+ lua_Debug ar;
+ int li = 1, le = 1;
+ /* find an upper bound */
+ while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
+ /* do a binary search */
+ while (li < le) {
+ int m = (li + le)/2;
+ if (lua_getstack(L, m, &ar)) li = m + 1;
+ else le = m;
+ }
+ return le - 1;
}
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
- const char *msg, int level) {
- lua_Debug ar;
- int top = lua_gettop(L);
- int numlevels = countlevels(L1);
- int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
- if (msg) lua_pushfstring(L, "%s\n", msg);
- lua_pushliteral(L, "stack traceback:");
- while (lua_getstack(L1, level++, &ar)) {
- if (level == mark) { /* too many levels? */
- lua_pushliteral(L, "\n\t..."); /* add a '...' */
- level = numlevels - LEVELS2; /* and skip to last ones */
- }
- else {
- lua_getinfo(L1, "Slnt", &ar);
- lua_pushfstring(L, "\n\t%s:", ar.short_src);
- if (ar.currentline > 0)
- lua_pushfstring(L, "%d:", ar.currentline);
- lua_pushliteral(L, " in ");
- pushfuncname(L, &ar);
- if (ar.istailcall)
- lua_pushliteral(L, "\n\t(...tail calls...)");
- lua_concat(L, lua_gettop(L) - top);
- }
- }
- lua_concat(L, lua_gettop(L) - top);
+ const char *msg, int level) {
+ lua_Debug ar;
+ int top = lua_gettop(L);
+ int numlevels = countlevels(L1);
+ int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
+ if (msg) lua_pushfstring(L, "%s\n", msg);
+ lua_pushliteral(L, "stack traceback:");
+ while (lua_getstack(L1, level++, &ar)) {
+ if (level == mark) { /* too many levels? */
+ lua_pushliteral(L, "\n\t..."); /* add a '...' */
+ level = numlevels - LEVELS2; /* and skip to last ones */
+ }
+ else {
+ lua_getinfo(L1, "Slnt", &ar);
+ lua_pushfstring(L, "\n\t%s:", ar.short_src);
+ if (ar.currentline > 0)
+ lua_pushfstring(L, "%d:", ar.currentline);
+ lua_pushliteral(L, " in ");
+ pushfuncname(L, &ar);
+ if (ar.istailcall)
+ lua_pushliteral(L, "\n\t(...tail calls...)");
+ lua_concat(L, lua_gettop(L) - top);
+ }
+ }
+ lua_concat(L, lua_gettop(L) - top);
}
/* }====================================================== */
@@ -151,78 +151,78 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
*/
LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
- lua_Debug ar;
- if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
- return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
- lua_getinfo(L, "n", &ar);
- if (strcmp(ar.namewhat, "method") == 0) {
- narg--; /* do not count `self' */
- if (narg == 0) /* error is in the self argument itself? */
- return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
- ar.name, extramsg);
- }
- if (ar.name == NULL)
- ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
- return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
- narg, ar.name, extramsg);
+ lua_Debug ar;
+ if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
+ return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
+ lua_getinfo(L, "n", &ar);
+ if (strcmp(ar.namewhat, "method") == 0) {
+ narg--; /* do not count `self' */
+ if (narg == 0) /* error is in the self argument itself? */
+ return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
+ ar.name, extramsg);
+ }
+ if (ar.name == NULL)
+ ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
+ return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
+ narg, ar.name, extramsg);
}
static int typeerror (lua_State *L, int narg, const char *tname) {
- const char *msg = lua_pushfstring(L, "%s expected, got %s",
- tname, luaL_typename(L, narg));
- return luaL_argerror(L, narg, msg);
+ const char *msg = lua_pushfstring(L, "%s expected, got %s",
+ tname, luaL_typename(L, narg));
+ return luaL_argerror(L, narg, msg);
}
static void tag_error (lua_State *L, int narg, int tag) {
- typeerror(L, narg, lua_typename(L, tag));
+ typeerror(L, narg, lua_typename(L, tag));
}
LUALIB_API void luaL_where (lua_State *L, int level) {
- lua_Debug ar;
- if (lua_getstack(L, level, &ar)) { /* check function at level */
- lua_getinfo(L, "Sl", &ar); /* get info about it */
- if (ar.currentline > 0) { /* is there info? */
- lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
- return;
- }
- }
- lua_pushliteral(L, ""); /* else, no information available... */
+ lua_Debug ar;
+ if (lua_getstack(L, level, &ar)) { /* check function at level */
+ lua_getinfo(L, "Sl", &ar); /* get info about it */
+ if (ar.currentline > 0) { /* is there info? */
+ lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
+ return;
+ }
+ }
+ lua_pushliteral(L, ""); /* else, no information available... */
}
LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
- va_list argp;
- va_start(argp, fmt);
- luaL_where(L, 1);
- lua_pushvfstring(L, fmt, argp);
- va_end(argp);
- lua_concat(L, 2);
- return lua_error(L);
+ va_list argp;
+ va_start(argp, fmt);
+ luaL_where(L, 1);
+ lua_pushvfstring(L, fmt, argp);
+ va_end(argp);
+ lua_concat(L, 2);
+ return lua_error(L);
}
LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
- int en = errno; /* calls to Lua API may change this value */
- if (stat) {
- lua_pushboolean(L, 1);
- return 1;
- }
- else {
- lua_pushnil(L);
- if (fname)
- lua_pushfstring(L, "%s: %s", fname, strerror(en));
- else
- lua_pushstring(L, strerror(en));
- lua_pushinteger(L, en);
- return 3;
- }
+ int en = errno; /* calls to Lua API may change this value */
+ if (stat) {
+ lua_pushboolean(L, 1);
+ return 1;
+ }
+ else {
+ lua_pushnil(L);
+ if (fname)
+ lua_pushfstring(L, "%s: %s", fname, strerror(en));
+ else
+ lua_pushstring(L, strerror(en));
+ lua_pushinteger(L, en);
+ return 3;
+ }
}
-#if !defined(inspectstat) /* { */
+#if !defined(inspectstat) /* { */
#if defined(LUA_USE_POSIX)
@@ -232,8 +232,8 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
** use appropriate macros to interpret 'pclose' return status
*/
#define inspectstat(stat,what) \
- if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \
- else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; }
+ if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \
+ else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; }
#else
@@ -241,23 +241,23 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
#endif
-#endif /* } */
+#endif /* } */
LUALIB_API int luaL_execresult (lua_State *L, int stat) {
- const char *what = "exit"; /* type of termination */
- if (stat == -1) /* error? */
- return luaL_fileresult(L, 0, NULL);
- else {
- inspectstat(stat, what); /* interpret result */
- if (*what == 'e' && stat == 0) /* successful termination? */
- lua_pushboolean(L, 1);
- else
- lua_pushnil(L);
- lua_pushstring(L, what);
- lua_pushinteger(L, stat);
- return 3; /* return true/nil,what,code */
- }
+ const char *what = "exit"; /* type of termination */
+ if (stat == -1) /* error? */
+ return luaL_fileresult(L, 0, NULL);
+ else {
+ inspectstat(stat, what); /* interpret result */
+ if (*what == 'e' && stat == 0) /* successful termination? */
+ lua_pushboolean(L, 1);
+ else
+ lua_pushnil(L);
+ lua_pushstring(L, what);
+ lua_pushinteger(L, stat);
+ return 3; /* return true/nil,what,code */
+ }
}
/* }====================================================== */
@@ -270,42 +270,42 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) {
*/
LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
- luaL_getmetatable(L, tname); /* try to get metatable */
- if (!lua_isnil(L, -1)) /* name already in use? */
- return 0; /* leave previous value on top, but return 0 */
- lua_pop(L, 1);
- lua_newtable(L); /* create metatable */
- lua_pushvalue(L, -1);
- lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
- return 1;
+ luaL_getmetatable(L, tname); /* try to get metatable */
+ if (!lua_isnil(L, -1)) /* name already in use? */
+ return 0; /* leave previous value on top, but return 0 */
+ lua_pop(L, 1);
+ lua_newtable(L); /* create metatable */
+ lua_pushvalue(L, -1);
+ lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
+ return 1;
}
LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
- luaL_getmetatable(L, tname);
- lua_setmetatable(L, -2);
+ luaL_getmetatable(L, tname);
+ lua_setmetatable(L, -2);
}
LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
- void *p = lua_touserdata(L, ud);
- if (p != NULL) { /* value is a userdata? */
- if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
- luaL_getmetatable(L, tname); /* get correct metatable */
- if (!lua_rawequal(L, -1, -2)) /* not the same? */
- p = NULL; /* value is a userdata with wrong metatable */
- lua_pop(L, 2); /* remove both metatables */
- return p;
- }
- }
- return NULL; /* value is not a userdata with a metatable */
+ void *p = lua_touserdata(L, ud);
+ if (p != NULL) { /* value is a userdata? */
+ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
+ luaL_getmetatable(L, tname); /* get correct metatable */
+ if (!lua_rawequal(L, -1, -2)) /* not the same? */
+ p = NULL; /* value is a userdata with wrong metatable */
+ lua_pop(L, 2); /* remove both metatables */
+ return p;
+ }
+ }
+ return NULL; /* value is not a userdata with a metatable */
}
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
- void *p = luaL_testudata(L, ud, tname);
- if (p == NULL) typeerror(L, ud, tname);
- return p;
+ void *p = luaL_testudata(L, ud, tname);
+ if (p == NULL) typeerror(L, ud, tname);
+ return p;
}
/* }====================================================== */
@@ -318,101 +318,101 @@ LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
*/
LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,
- const char *const lst[]) {
- const char *name = (def) ? luaL_optstring(L, narg, def) :
- luaL_checkstring(L, narg);
- int i;
- for (i=0; lst[i]; i++)
- if (strcmp(lst[i], name) == 0)
- return i;
- return luaL_argerror(L, narg,
- lua_pushfstring(L, "invalid option " LUA_QS, name));
+ const char *const lst[]) {
+ const char *name = (def) ? luaL_optstring(L, narg, def) :
+ luaL_checkstring(L, narg);
+ int i;
+ for (i=0; lst[i]; i++)
+ if (strcmp(lst[i], name) == 0)
+ return i;
+ return luaL_argerror(L, narg,
+ lua_pushfstring(L, "invalid option " LUA_QS, name));
}
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {
- /* keep some extra space to run error routines, if needed */
- const int extra = LUA_MINSTACK;
- if (!lua_checkstack(L, space + extra)) {
- if (msg)
- luaL_error(L, "stack overflow (%s)", msg);
- else
- luaL_error(L, "stack overflow");
- }
+ /* keep some extra space to run error routines, if needed */
+ const int extra = LUA_MINSTACK;
+ if (!lua_checkstack(L, space + extra)) {
+ if (msg)
+ luaL_error(L, "stack overflow (%s)", msg);
+ else
+ luaL_error(L, "stack overflow");
+ }
}
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
- if (lua_type(L, narg) != t)
- tag_error(L, narg, t);
+ if (lua_type(L, narg) != t)
+ tag_error(L, narg, t);
}
LUALIB_API void luaL_checkany (lua_State *L, int narg) {
- if (lua_type(L, narg) == LUA_TNONE)
- luaL_argerror(L, narg, "value expected");
+ if (lua_type(L, narg) == LUA_TNONE)
+ luaL_argerror(L, narg, "value expected");
}
LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
- const char *s = lua_tolstring(L, narg, len);
- if (!s) tag_error(L, narg, LUA_TSTRING);
- return s;
+ const char *s = lua_tolstring(L, narg, len);
+ if (!s) tag_error(L, narg, LUA_TSTRING);
+ return s;
}
LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
- const char *def, size_t *len) {
- if (lua_isnoneornil(L, narg)) {
- if (len)
- *len = (def ? strlen(def) : 0);
- return def;
- }
- else return luaL_checklstring(L, narg, len);
+ const char *def, size_t *len) {
+ if (lua_isnoneornil(L, narg)) {
+ if (len)
+ *len = (def ? strlen(def) : 0);
+ return def;
+ }
+ else return luaL_checklstring(L, narg, len);
}
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {
- int isnum;
- lua_Number d = lua_tonumberx(L, narg, &isnum);
- if (!isnum)
- tag_error(L, narg, LUA_TNUMBER);
- return d;
+ int isnum;
+ lua_Number d = lua_tonumberx(L, narg, &isnum);
+ if (!isnum)
+ tag_error(L, narg, LUA_TNUMBER);
+ return d;
}
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
- return luaL_opt(L, luaL_checknumber, narg, def);
+ return luaL_opt(L, luaL_checknumber, narg, def);
}
LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
- int isnum;
- lua_Integer d = lua_tointegerx(L, narg, &isnum);
- if (!isnum)
- tag_error(L, narg, LUA_TNUMBER);
- return d;
+ int isnum;
+ lua_Integer d = lua_tointegerx(L, narg, &isnum);
+ if (!isnum)
+ tag_error(L, narg, LUA_TNUMBER);
+ return d;
}
LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg) {
- int isnum;
- lua_Unsigned d = lua_tounsignedx(L, narg, &isnum);
- if (!isnum)
- tag_error(L, narg, LUA_TNUMBER);
- return d;
+ int isnum;
+ lua_Unsigned d = lua_tounsignedx(L, narg, &isnum);
+ if (!isnum)
+ tag_error(L, narg, LUA_TNUMBER);
+ return d;
}
LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
- lua_Integer def) {
- return luaL_opt(L, luaL_checkinteger, narg, def);
+ lua_Integer def) {
+ return luaL_opt(L, luaL_checkinteger, narg, def);
}
LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg,
- lua_Unsigned def) {
- return luaL_opt(L, luaL_checkunsigned, narg, def);
+ lua_Unsigned def) {
+ return luaL_opt(L, luaL_checkunsigned, narg, def);
}
/* }====================================================== */
@@ -428,82 +428,82 @@ LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg,
** check whether buffer is using a userdata on the stack as a temporary
** buffer
*/
-#define buffonstack(B) ((B)->b != (B)->initb)
+#define buffonstack(B) ((B)->b != (B)->initb)
/*
** returns a pointer to a free area with at least 'sz' bytes
*/
LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
- lua_State *L = B->L;
- if (B->size - B->n < sz) { /* not enough space? */
- char *newbuff;
- size_t newsize = B->size * 2; /* double buffer size */
- if (newsize - B->n < sz) /* not big enough? */
- newsize = B->n + sz;
- if (newsize < B->n || newsize - B->n < sz)
- luaL_error(L, "buffer too large");
- /* create larger buffer */
- newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
- /* move content to new buffer */
- memcpy(newbuff, B->b, B->n * sizeof(char));
- if (buffonstack(B))
- lua_remove(L, -2); /* remove old buffer */
- B->b = newbuff;
- B->size = newsize;
- }
- return &B->b[B->n];
+ lua_State *L = B->L;
+ if (B->size - B->n < sz) { /* not enough space? */
+ char *newbuff;
+ size_t newsize = B->size * 2; /* double buffer size */
+ if (newsize - B->n < sz) /* not big enough? */
+ newsize = B->n + sz;
+ if (newsize < B->n || newsize - B->n < sz)
+ luaL_error(L, "buffer too large");
+ /* create larger buffer */
+ newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
+ /* move content to new buffer */
+ memcpy(newbuff, B->b, B->n * sizeof(char));
+ if (buffonstack(B))
+ lua_remove(L, -2); /* remove old buffer */
+ B->b = newbuff;
+ B->size = newsize;
+ }
+ return &B->b[B->n];
}
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
- char *b = luaL_prepbuffsize(B, l);
- memcpy(b, s, l * sizeof(char));
- luaL_addsize(B, l);
+ char *b = luaL_prepbuffsize(B, l);
+ memcpy(b, s, l * sizeof(char));
+ luaL_addsize(B, l);
}
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
- luaL_addlstring(B, s, strlen(s));
+ luaL_addlstring(B, s, strlen(s));
}
LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
- lua_State *L = B->L;
- lua_pushlstring(L, B->b, B->n);
- if (buffonstack(B))
- lua_remove(L, -2); /* remove old buffer */
+ lua_State *L = B->L;
+ lua_pushlstring(L, B->b, B->n);
+ if (buffonstack(B))
+ lua_remove(L, -2); /* remove old buffer */
}
LUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {
- luaL_addsize(B, sz);
- luaL_pushresult(B);
+ luaL_addsize(B, sz);
+ luaL_pushresult(B);
}
LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
- lua_State *L = B->L;
- size_t l;
- const char *s = lua_tolstring(L, -1, &l);
- if (buffonstack(B))
- lua_insert(L, -2); /* put value below buffer */
- luaL_addlstring(B, s, l);
- lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */
+ lua_State *L = B->L;
+ size_t l;
+ const char *s = lua_tolstring(L, -1, &l);
+ if (buffonstack(B))
+ lua_insert(L, -2); /* put value below buffer */
+ luaL_addlstring(B, s, l);
+ lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */
}
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
- B->L = L;
- B->b = B->initb;
- B->n = 0;
- B->size = LUAL_BUFFERSIZE;
+ B->L = L;
+ B->b = B->initb;
+ B->n = 0;
+ B->size = LUAL_BUFFERSIZE;
}
LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {
- luaL_buffinit(L, B);
- return luaL_prepbuffsize(B, sz);
+ luaL_buffinit(L, B);
+ return luaL_prepbuffsize(B, sz);
}
/* }====================================================== */
@@ -516,38 +516,38 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {
*/
/* index of free-list header */
-#define freelist 0
+#define freelist 0
LUALIB_API int luaL_ref (lua_State *L, int t) {
- int ref;
- if (lua_isnil(L, -1)) {
- lua_pop(L, 1); /* remove from stack */
- return LUA_REFNIL; /* `nil' has a unique fixed reference */
- }
- t = lua_absindex(L, t);
- lua_rawgeti(L, t, freelist); /* get first free element */
- ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
- lua_pop(L, 1); /* remove it from stack */
- if (ref != 0) { /* any free element? */
- lua_rawgeti(L, t, ref); /* remove it from list */
- lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
- }
- else /* no free elements */
- ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
- lua_rawseti(L, t, ref);
- return ref;
+ int ref;
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 1); /* remove from stack */
+ return LUA_REFNIL; /* `nil' has a unique fixed reference */
+ }
+ t = lua_absindex(L, t);
+ lua_rawgeti(L, t, freelist); /* get first free element */
+ ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
+ lua_pop(L, 1); /* remove it from stack */
+ if (ref != 0) { /* any free element? */
+ lua_rawgeti(L, t, ref); /* remove it from list */
+ lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
+ }
+ else /* no free elements */
+ ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
+ lua_rawseti(L, t, ref);
+ return ref;
}
LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
- if (ref >= 0) {
- t = lua_absindex(L, t);
- lua_rawgeti(L, t, freelist);
- lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
- lua_pushinteger(L, ref);
- lua_rawseti(L, t, freelist); /* t[freelist] = ref */
- }
+ if (ref >= 0) {
+ t = lua_absindex(L, t);
+ lua_rawgeti(L, t, freelist);
+ lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
+ lua_pushinteger(L, ref);
+ lua_rawseti(L, t, freelist); /* t[freelist] = ref */
+ }
}
/* }====================================================== */
@@ -560,50 +560,50 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
*/
typedef struct LoadF {
- int n; /* number of pre-read characters */
- FILE *f; /* file being read */
- char buff[LUAL_BUFFERSIZE]; /* area for reading file */
+ int n; /* number of pre-read characters */
+ FILE *f; /* file being read */
+ char buff[LUAL_BUFFERSIZE]; /* area for reading file */
} LoadF;
static const char *getF (lua_State *L, void *ud, size_t *size) {
- LoadF *lf = (LoadF *)ud;
- (void)L; /* not used */
- if (lf->n > 0) { /* are there pre-read characters to be read? */
- *size = lf->n; /* return them (chars already in buffer) */
- lf->n = 0; /* no more pre-read characters */
- }
- else { /* read a block from file */
- /* 'fread' can return > 0 *and* set the EOF flag. If next call to
- 'getF' called 'fread', it might still wait for user input.
- The next check avoids this problem. */
- if (feof(lf->f)) return NULL;
- *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
- }
- return lf->buff;
+ LoadF *lf = (LoadF *)ud;
+ (void)L; /* not used */
+ if (lf->n > 0) { /* are there pre-read characters to be read? */
+ *size = lf->n; /* return them (chars already in buffer) */
+ lf->n = 0; /* no more pre-read characters */
+ }
+ else { /* read a block from file */
+ /* 'fread' can return > 0 *and* set the EOF flag. If next call to
+ 'getF' called 'fread', it might still wait for user input.
+ The next check avoids this problem. */
+ if (feof(lf->f)) return NULL;
+ *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
+ }
+ return lf->buff;
}
static int errfile (lua_State *L, const char *what, int fnameindex) {
- const char *serr = strerror(errno);
- const char *filename = lua_tostring(L, fnameindex) + 1;
- lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
- lua_remove(L, fnameindex);
- return LUA_ERRFILE;
+ const char *serr = strerror(errno);
+ const char *filename = lua_tostring(L, fnameindex) + 1;
+ lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
+ lua_remove(L, fnameindex);
+ return LUA_ERRFILE;
}
static int skipBOM (LoadF *lf) {
- const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
- int c;
- lf->n = 0;
- do {
- c = getc(lf->f);
- if (c == EOF || c != *(const unsigned char *)p++) return c;
- lf->buff[lf->n++] = c; /* to be read by the parser */
- } while (*p != '\0');
- lf->n = 0; /* prefix matched; discard it */
- return getc(lf->f); /* return next character */
+ const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
+ int c;
+ lf->n = 0;
+ do {
+ c = getc(lf->f);
+ if (c == EOF || c != *(const unsigned char *)p++) return c;
+ lf->buff[lf->n++] = c; /* to be read by the parser */
+ } while (*p != '\0');
+ lf->n = 0; /* prefix matched; discard it */
+ return getc(lf->f); /* return next character */
}
@@ -615,81 +615,81 @@ static int skipBOM (LoadF *lf) {
** a first-line comment).
*/
static int skipcomment (LoadF *lf, int *cp) {
- int c = *cp = skipBOM(lf);
- if (c == '#') { /* first line is a comment (Unix exec. file)? */
- do { /* skip first line */
- c = getc(lf->f);
- } while (c != EOF && c != '\n') ;
- *cp = getc(lf->f); /* skip end-of-line, if present */
- return 1; /* there was a comment */
- }
- else return 0; /* no comment */
+ int c = *cp = skipBOM(lf);
+ if (c == '#') { /* first line is a comment (Unix exec. file)? */
+ do { /* skip first line */
+ c = getc(lf->f);
+ } while (c != EOF && c != '\n') ;
+ *cp = getc(lf->f); /* skip end-of-line, if present */
+ return 1; /* there was a comment */
+ }
+ else return 0; /* no comment */
}
LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
- const char *mode) {
- LoadF lf;
- int status, readstatus;
- int c;
- int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
- if (filename == NULL) {
- lua_pushliteral(L, "=stdin");
- lf.f = stdin;
- }
- else {
- lua_pushfstring(L, "@%s", filename);
- lf.f = fopen(filename, "r");
- if (lf.f == NULL) return errfile(L, "open", fnameindex);
- }
- if (skipcomment(&lf, &c)) /* read initial portion */
- lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
- if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
- lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
- if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
- skipcomment(&lf, &c); /* re-read initial portion */
- }
- if (c != EOF)
- lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
- status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
- readstatus = ferror(lf.f);
- if (filename) fclose(lf.f); /* close file (even in case of errors) */
- if (readstatus) {
- lua_settop(L, fnameindex); /* ignore results from `lua_load' */
- return errfile(L, "read", fnameindex);
- }
- lua_remove(L, fnameindex);
- return status;
+ const char *mode) {
+ LoadF lf;
+ int status, readstatus;
+ int c;
+ int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
+ if (filename == NULL) {
+ lua_pushliteral(L, "=stdin");
+ lf.f = stdin;
+ }
+ else {
+ lua_pushfstring(L, "@%s", filename);
+ lf.f = fopen(filename, "r");
+ if (lf.f == NULL) return errfile(L, "open", fnameindex);
+ }
+ if (skipcomment(&lf, &c)) /* read initial portion */
+ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
+ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
+ lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
+ if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
+ skipcomment(&lf, &c); /* re-read initial portion */
+ }
+ if (c != EOF)
+ lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
+ status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
+ readstatus = ferror(lf.f);
+ if (filename) fclose(lf.f); /* close file (even in case of errors) */
+ if (readstatus) {
+ lua_settop(L, fnameindex); /* ignore results from `lua_load' */
+ return errfile(L, "read", fnameindex);
+ }
+ lua_remove(L, fnameindex);
+ return status;
}
typedef struct LoadS {
- const char *s;
- size_t size;
+ const char *s;
+ size_t size;
} LoadS;
static const char *getS (lua_State *L, void *ud, size_t *size) {
- LoadS *ls = (LoadS *)ud;
- (void)L; /* not used */
- if (ls->size == 0) return NULL;
- *size = ls->size;
- ls->size = 0;
- return ls->s;
+ LoadS *ls = (LoadS *)ud;
+ (void)L; /* not used */
+ if (ls->size == 0) return NULL;
+ *size = ls->size;
+ ls->size = 0;
+ return ls->s;
}
LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,
- const char *name, const char *mode) {
- LoadS ls;
- ls.s = buff;
- ls.size = size;
- return lua_load(L, getS, &ls, name, mode);
+ const char *name, const char *mode) {
+ LoadS ls;
+ ls.s = buff;
+ ls.size = size;
+ return lua_load(L, getS, &ls, name, mode);
}
LUALIB_API int luaL_loadstring (lua_State *L, const char *s) {
- return luaL_loadbuffer(L, s, strlen(s), s);
+ return luaL_loadbuffer(L, s, strlen(s), s);
}
/* }====================================================== */
@@ -697,63 +697,63 @@ LUALIB_API int luaL_loadstring (lua_State *L, const char *s) {
LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
- if (!lua_getmetatable(L, obj)) /* no metatable? */
- return 0;
- lua_pushstring(L, event);
- lua_rawget(L, -2);
- if (lua_isnil(L, -1)) {
- lua_pop(L, 2); /* remove metatable and metafield */
- return 0;
- }
- else {
- lua_remove(L, -2); /* remove only metatable */
- return 1;
- }
+ if (!lua_getmetatable(L, obj)) /* no metatable? */
+ return 0;
+ lua_pushstring(L, event);
+ lua_rawget(L, -2);
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 2); /* remove metatable and metafield */
+ return 0;
+ }
+ else {
+ lua_remove(L, -2); /* remove only metatable */
+ return 1;
+ }
}
LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
- obj = lua_absindex(L, obj);
- if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
- return 0;
- lua_pushvalue(L, obj);
- lua_call(L, 1, 1);
- return 1;
+ obj = lua_absindex(L, obj);
+ if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
+ return 0;
+ lua_pushvalue(L, obj);
+ lua_call(L, 1, 1);
+ return 1;
}
LUALIB_API int luaL_len (lua_State *L, int idx) {
- int l;
- int isnum;
- lua_len(L, idx);
- l = (int)lua_tointegerx(L, -1, &isnum);
- if (!isnum)
- luaL_error(L, "object length is not a number");
- lua_pop(L, 1); /* remove object */
- return l;
+ int l;
+ int isnum;
+ lua_len(L, idx);
+ l = (int)lua_tointegerx(L, -1, &isnum);
+ if (!isnum)
+ luaL_error(L, "object length is not a number");
+ lua_pop(L, 1); /* remove object */
+ return l;
}
LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
- if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
- switch (lua_type(L, idx)) {
- case LUA_TNUMBER:
- case LUA_TSTRING:
- lua_pushvalue(L, idx);
- break;
- case LUA_TBOOLEAN:
- lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
- break;
- case LUA_TNIL:
- lua_pushliteral(L, "nil");
- break;
- default:
- lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
- lua_topointer(L, idx));
- break;
- }
- }
- return lua_tolstring(L, -1, len);
+ if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
+ switch (lua_type(L, idx)) {
+ case LUA_TNUMBER:
+ case LUA_TSTRING:
+ lua_pushvalue(L, idx);
+ break;
+ case LUA_TBOOLEAN:
+ lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
+ break;
+ case LUA_TNIL:
+ lua_pushliteral(L, "nil");
+ break;
+ default:
+ lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
+ lua_topointer(L, idx));
+ break;
+ }
+ }
+ return lua_tolstring(L, -1, len);
}
@@ -765,29 +765,29 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
#if defined(LUA_COMPAT_MODULE)
static const char *luaL_findtable (lua_State *L, int idx,
- const char *fname, int szhint) {
- const char *e;
- if (idx) lua_pushvalue(L, idx);
- do {
- e = strchr(fname, '.');
- if (e == NULL) e = fname + strlen(fname);
- lua_pushlstring(L, fname, e - fname);
- lua_rawget(L, -2);
- if (lua_isnil(L, -1)) { /* no such field? */
- lua_pop(L, 1); /* remove this nil */
- lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
- lua_pushlstring(L, fname, e - fname);
- lua_pushvalue(L, -2);
- lua_settable(L, -4); /* set new table into field */
- }
- else if (!lua_istable(L, -1)) { /* field has a non-table value? */
- lua_pop(L, 2); /* remove table and value */
- return fname; /* return problematic part of the name */
- }
- lua_remove(L, -2); /* remove previous table */
- fname = e + 1;
- } while (*e == '.');
- return NULL;
+ const char *fname, int szhint) {
+ const char *e;
+ if (idx) lua_pushvalue(L, idx);
+ do {
+ e = strchr(fname, '.');
+ if (e == NULL) e = fname + strlen(fname);
+ lua_pushlstring(L, fname, e - fname);
+ lua_rawget(L, -2);
+ if (lua_isnil(L, -1)) { /* no such field? */
+ lua_pop(L, 1); /* remove this nil */
+ lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
+ lua_pushlstring(L, fname, e - fname);
+ lua_pushvalue(L, -2);
+ lua_settable(L, -4); /* set new table into field */
+ }
+ else if (!lua_istable(L, -1)) { /* field has a non-table value? */
+ lua_pop(L, 2); /* remove table and value */
+ return fname; /* return problematic part of the name */
+ }
+ lua_remove(L, -2); /* remove previous table */
+ fname = e + 1;
+ } while (*e == '.');
+ return NULL;
}
@@ -795,9 +795,9 @@ static const char *luaL_findtable (lua_State *L, int idx,
** Count number of elements in a luaL_Reg list.
*/
static int libsize (const luaL_Reg *l) {
- int size = 0;
- for (; l && l->name; l++) size++;
- return size;
+ int size = 0;
+ for (; l && l->name; l++) size++;
+ return size;
}
@@ -808,33 +808,33 @@ static int libsize (const luaL_Reg *l) {
** the module table.
*/
LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
- int sizehint) {
- luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
- lua_getfield(L, -1, modname); /* get _LOADED[modname] */
- if (!lua_istable(L, -1)) { /* not found? */
- lua_pop(L, 1); /* remove previous result */
- /* try global variable (and create one if it does not exist) */
- lua_pushglobaltable(L);
- if (luaL_findtable(L, 0, modname, sizehint) != NULL)
- luaL_error(L, "name conflict for module " LUA_QS, modname);
- lua_pushvalue(L, -1);
- lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
- }
- lua_remove(L, -2); /* remove _LOADED table */
+ int sizehint) {
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
+ lua_getfield(L, -1, modname); /* get _LOADED[modname] */
+ if (!lua_istable(L, -1)) { /* not found? */
+ lua_pop(L, 1); /* remove previous result */
+ /* try global variable (and create one if it does not exist) */
+ lua_pushglobaltable(L);
+ if (luaL_findtable(L, 0, modname, sizehint) != NULL)
+ luaL_error(L, "name conflict for module " LUA_QS, modname);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
+ }
+ lua_remove(L, -2); /* remove _LOADED table */
}
LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
- const luaL_Reg *l, int nup) {
- luaL_checkversion(L);
- if (libname) {
- luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
- lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
- }
- if (l)
- luaL_setfuncs(L, l, nup);
- else
- lua_pop(L, nup); /* remove upvalues */
+ const luaL_Reg *l, int nup) {
+ luaL_checkversion(L);
+ if (libname) {
+ luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
+ lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
+ }
+ if (l)
+ luaL_setfuncs(L, l, nup);
+ else
+ lua_pop(L, nup); /* remove upvalues */
}
#endif
@@ -846,16 +846,16 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
** Returns with only the table at the stack.
*/
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
- luaL_checkversion(L);
- luaL_checkstack(L, nup, "too many upvalues");
- for (; l->name != NULL; l++) { /* fill the table with given functions */
- int i;
- for (i = 0; i < nup; i++) /* copy upvalues to the top */
- lua_pushvalue(L, -nup);
- lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
- lua_setfield(L, -(nup + 2), l->name);
- }
- lua_pop(L, nup); /* remove upvalues */
+ luaL_checkversion(L);
+ luaL_checkstack(L, nup, "too many upvalues");
+ for (; l->name != NULL; l++) { /* fill the table with given functions */
+ int i;
+ for (i = 0; i < nup; i++) /* copy upvalues to the top */
+ lua_pushvalue(L, -nup);
+ lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
+ lua_setfield(L, -(nup + 2), l->name);
+ }
+ lua_pop(L, nup); /* remove upvalues */
}
@@ -864,16 +864,16 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
** into the stack
*/
LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
- lua_getfield(L, idx, fname);
- if (lua_istable(L, -1)) return 1; /* table already there */
- else {
- lua_pop(L, 1); /* remove previous result */
- idx = lua_absindex(L, idx);
- lua_newtable(L);
- lua_pushvalue(L, -1); /* copy to be left at top */
- lua_setfield(L, idx, fname); /* assign new table to field */
- return 0; /* false, because did not find table there */
- }
+ lua_getfield(L, idx, fname);
+ if (lua_istable(L, -1)) return 1; /* table already there */
+ else {
+ lua_pop(L, 1); /* remove previous result */
+ idx = lua_absindex(L, idx);
+ lua_newtable(L);
+ lua_pushvalue(L, -1); /* copy to be left at top */
+ lua_setfield(L, idx, fname); /* assign new table to field */
+ return 0; /* false, because did not find table there */
+ }
}
@@ -884,76 +884,75 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
** Leaves resulting module on the top.
*/
LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
- lua_CFunction openf, int glb) {
- lua_pushcfunction(L, openf);
- lua_pushstring(L, modname); /* argument to open function */
- lua_call(L, 1, 1); /* open module */
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_pushvalue(L, -2); /* make copy of module (call result) */
- lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
- lua_pop(L, 1); /* remove _LOADED table */
- if (glb) {
- lua_pushvalue(L, -1); /* copy of 'mod' */
- lua_setglobal(L, modname); /* _G[modname] = module */
- }
+ lua_CFunction openf, int glb) {
+ lua_pushcfunction(L, openf);
+ lua_pushstring(L, modname); /* argument to open function */
+ lua_call(L, 1, 1); /* open module */
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_pushvalue(L, -2); /* make copy of module (call result) */
+ lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
+ lua_pop(L, 1); /* remove _LOADED table */
+ if (glb) {
+ lua_pushvalue(L, -1); /* copy of 'mod' */
+ lua_setglobal(L, modname); /* _G[modname] = module */
+ }
}
LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
- const char *r) {
- const char *wild;
- size_t l = strlen(p);
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- while ((wild = strstr(s, p)) != NULL) {
- luaL_addlstring(&b, s, wild - s); /* push prefix */
- luaL_addstring(&b, r); /* push replacement in place of pattern */
- s = wild + l; /* continue after `p' */
- }
- luaL_addstring(&b, s); /* push last suffix */
- luaL_pushresult(&b);
- return lua_tostring(L, -1);
+ const char *r) {
+ const char *wild;
+ size_t l = strlen(p);
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ while ((wild = strstr(s, p)) != NULL) {
+ luaL_addlstring(&b, s, wild - s); /* push prefix */
+ luaL_addstring(&b, r); /* push replacement in place of pattern */
+ s = wild + l; /* continue after `p' */
+ }
+ luaL_addstring(&b, s); /* push last suffix */
+ luaL_pushresult(&b);
+ return lua_tostring(L, -1);
}
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
- (void)ud; (void)osize; /* not used */
- if (nsize == 0) {
- free(ptr);
- return NULL;
- }
- else
- return realloc(ptr, nsize);
+ (void)ud; (void)osize; /* not used */
+ if (nsize == 0) {
+ free(ptr);
+ return NULL;
+ }
+ else
+ return realloc(ptr, nsize);
}
static int panic (lua_State *L) {
- luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
- lua_tostring(L, -1));
- return 0; /* return to Lua to abort */
+ luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
+ lua_tostring(L, -1));
+ return 0; /* return to Lua to abort */
}
LUALIB_API lua_State *luaL_newstate (void) {
- lua_State *L = lua_newstate(l_alloc, NULL);
- if (L) lua_atpanic(L, &panic);
- return L;
+ lua_State *L = lua_newstate(l_alloc, NULL);
+ if (L) lua_atpanic(L, &panic);
+ return L;
}
LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) {
- const lua_Number *v = lua_version(L);
- if (v != lua_version(NULL))
- luaL_error(L, "multiple Lua VMs detected");
- else if (*v != ver)
- luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
- ver, *v);
- /* check conversions number -> integer types */
- lua_pushnumber(L, -(lua_Number)0x1234);
- if (lua_tointeger(L, -1) != -0x1234 ||
- lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
- luaL_error(L, "bad conversion number->int;"
- " must recompile Lua with proper settings");
- lua_pop(L, 1);
+ const lua_Number *v = lua_version(L);
+ if (v != lua_version(NULL))
+ luaL_error(L, "multiple Lua VMs detected");
+ else if (*v != ver)
+ luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
+ ver, *v);
+ /* check conversions number -> integer types */
+ lua_pushnumber(L, -(lua_Number)0x1234);
+ if (lua_tointeger(L, -1) != -0x1234 ||
+ lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
+ luaL_error(L, "bad conversion number->int;"
+ " must recompile Lua with proper settings");
+ lua_pop(L, 1);
}
-
diff --git a/src/lib/lua/lauxlib.h b/src/lib/lua/lauxlib.h
index ac4d15fbb94..b7fcda3f443 100644
--- a/src/lib/lua/lauxlib.h
+++ b/src/lib/lua/lauxlib.h
@@ -21,31 +21,31 @@
typedef struct luaL_Reg {
- const char *name;
- lua_CFunction func;
+ const char *name;
+ lua_CFunction func;
} luaL_Reg;
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
-#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)
+#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
- size_t *l);
+ size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
- const char *def, size_t *l);
+ const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
- lua_Integer def);
+ lua_Integer def);
LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);
LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,
- lua_Unsigned def);
+ lua_Unsigned def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
@@ -60,7 +60,7 @@ LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
- const char *const lst[]);
+ const char *const lst[]);
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
@@ -73,12 +73,12 @@ LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
- const char *mode);
+ const char *mode);
-#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
+#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
- const char *name, const char *mode);
+ const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
@@ -86,17 +86,17 @@ LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API int (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
- const char *r);
+ const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
- const char *msg, int level);
+ const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
- lua_CFunction openf, int glb);
+ lua_CFunction openf, int glb);
/*
** ===============================================================
@@ -105,21 +105,21 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
*/
-#define luaL_newlibtable(L,l) \
- lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
+#define luaL_newlibtable(L,l) \
+ lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
-#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
+#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
-#define luaL_argcheck(L, cond,numarg,extramsg) \
+#define luaL_argcheck(L, cond,numarg,extramsg) \
((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
-#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
-#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
-#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
-#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
-#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
-#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
+#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
+#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
+#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
+#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
-#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
+#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
@@ -127,11 +127,11 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
-#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
+#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
-#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
+#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
-#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
+#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/*
@@ -141,19 +141,19 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
*/
typedef struct luaL_Buffer {
- char *b; /* buffer address */
- size_t size; /* buffer size */
- size_t n; /* number of characters in buffer */
- lua_State *L;
- char initb[LUAL_BUFFERSIZE]; /* initial buffer */
+ char *b; /* buffer address */
+ size_t size; /* buffer size */
+ size_t n; /* number of characters in buffer */
+ lua_State *L;
+ char initb[LUAL_BUFFERSIZE]; /* initial buffer */
} luaL_Buffer;
#define luaL_addchar(B,c) \
- ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
- ((B)->b[(B)->n++] = (c)))
+ ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
+ ((B)->b[(B)->n++] = (c)))
-#define luaL_addsize(B,s) ((B)->n += (s))
+#define luaL_addsize(B,s) ((B)->n += (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
@@ -164,7 +164,7 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
-#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
+#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
@@ -186,8 +186,8 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
typedef struct luaL_Stream {
- FILE *f; /* stream (NULL for incompletely created streams) */
- lua_CFunction closef; /* to close stream (NULL for closed streams) */
+ FILE *f; /* stream (NULL for incompletely created streams) */
+ lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
@@ -198,15 +198,13 @@ typedef struct luaL_Stream {
#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
- int sizehint);
+ int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
- const luaL_Reg *l, int nup);
+ const luaL_Reg *l, int nup);
-#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
+#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
#endif
-
-
diff --git a/src/lib/lua/lbaselib.c b/src/lib/lua/lbaselib.c
index 540e9a5cc03..96707e573a8 100644
--- a/src/lib/lua/lbaselib.c
+++ b/src/lib/lua/lbaselib.c
@@ -21,250 +21,250 @@
static int luaB_print (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- int i;
- lua_getglobal(L, "tostring");
- for (i=1; i<=n; i++) {
- const char *s;
- size_t l;
- lua_pushvalue(L, -1); /* function to be called */
- lua_pushvalue(L, i); /* value to print */
- lua_call(L, 1, 1);
- s = lua_tolstring(L, -1, &l); /* get result */
- if (s == NULL)
- return luaL_error(L,
- LUA_QL("tostring") " must return a string to " LUA_QL("print"));
- if (i>1) luai_writestring("\t", 1);
- luai_writestring(s, l);
- lua_pop(L, 1); /* pop result */
- }
- luai_writeline();
- return 0;
+ int n = lua_gettop(L); /* number of arguments */
+ int i;
+ lua_getglobal(L, "tostring");
+ for (i=1; i<=n; i++) {
+ const char *s;
+ size_t l;
+ lua_pushvalue(L, -1); /* function to be called */
+ lua_pushvalue(L, i); /* value to print */
+ lua_call(L, 1, 1);
+ s = lua_tolstring(L, -1, &l); /* get result */
+ if (s == NULL)
+ return luaL_error(L,
+ LUA_QL("tostring") " must return a string to " LUA_QL("print"));
+ if (i>1) luai_writestring("\t", 1);
+ luai_writestring(s, l);
+ lua_pop(L, 1); /* pop result */
+ }
+ luai_writeline();
+ return 0;
}
-#define SPACECHARS " \f\n\r\t\v"
+#define SPACECHARS " \f\n\r\t\v"
static int luaB_tonumber (lua_State *L) {
- if (lua_isnoneornil(L, 2)) { /* standard conversion */
- int isnum;
- lua_Number n = lua_tonumberx(L, 1, &isnum);
- if (isnum) {
- lua_pushnumber(L, n);
- return 1;
- } /* else not a number; must be something */
- luaL_checkany(L, 1);
- }
- else {
- size_t l;
- const char *s = luaL_checklstring(L, 1, &l);
- const char *e = s + l; /* end point for 's' */
- int base = luaL_checkint(L, 2);
- int neg = 0;
- luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
- s += strspn(s, SPACECHARS); /* skip initial spaces */
- if (*s == '-') { s++; neg = 1; } /* handle signal */
- else if (*s == '+') s++;
- if (isalnum((unsigned char)*s)) {
- lua_Number n = 0;
- do {
- int digit = (isdigit((unsigned char)*s)) ? *s - '0'
- : toupper((unsigned char)*s) - 'A' + 10;
- if (digit >= base) break; /* invalid numeral; force a fail */
- n = n * (lua_Number)base + (lua_Number)digit;
- s++;
- } while (isalnum((unsigned char)*s));
- s += strspn(s, SPACECHARS); /* skip trailing spaces */
- if (s == e) { /* no invalid trailing characters? */
- lua_pushnumber(L, (neg) ? -n : n);
- return 1;
- } /* else not a number */
- } /* else not a number */
- }
- lua_pushnil(L); /* not a number */
- return 1;
+ if (lua_isnoneornil(L, 2)) { /* standard conversion */
+ int isnum;
+ lua_Number n = lua_tonumberx(L, 1, &isnum);
+ if (isnum) {
+ lua_pushnumber(L, n);
+ return 1;
+ } /* else not a number; must be something */
+ luaL_checkany(L, 1);
+ }
+ else {
+ size_t l;
+ const char *s = luaL_checklstring(L, 1, &l);
+ const char *e = s + l; /* end point for 's' */
+ int base = luaL_checkint(L, 2);
+ int neg = 0;
+ luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
+ s += strspn(s, SPACECHARS); /* skip initial spaces */
+ if (*s == '-') { s++; neg = 1; } /* handle signal */
+ else if (*s == '+') s++;
+ if (isalnum((unsigned char)*s)) {
+ lua_Number n = 0;
+ do {
+ int digit = (isdigit((unsigned char)*s)) ? *s - '0'
+ : toupper((unsigned char)*s) - 'A' + 10;
+ if (digit >= base) break; /* invalid numeral; force a fail */
+ n = n * (lua_Number)base + (lua_Number)digit;
+ s++;
+ } while (isalnum((unsigned char)*s));
+ s += strspn(s, SPACECHARS); /* skip trailing spaces */
+ if (s == e) { /* no invalid trailing characters? */
+ lua_pushnumber(L, (neg) ? -n : n);
+ return 1;
+ } /* else not a number */
+ } /* else not a number */
+ }
+ lua_pushnil(L); /* not a number */
+ return 1;
}
static int luaB_error (lua_State *L) {
- int level = luaL_optint(L, 2, 1);
- lua_settop(L, 1);
- if (lua_isstring(L, 1) && level > 0) { /* add extra information? */
- luaL_where(L, level);
- lua_pushvalue(L, 1);
- lua_concat(L, 2);
- }
- return lua_error(L);
+ int level = luaL_optint(L, 2, 1);
+ lua_settop(L, 1);
+ if (lua_isstring(L, 1) && level > 0) { /* add extra information? */
+ luaL_where(L, level);
+ lua_pushvalue(L, 1);
+ lua_concat(L, 2);
+ }
+ return lua_error(L);
}
static int luaB_getmetatable (lua_State *L) {
- luaL_checkany(L, 1);
- if (!lua_getmetatable(L, 1)) {
- lua_pushnil(L);
- return 1; /* no metatable */
- }
- luaL_getmetafield(L, 1, "__metatable");
- return 1; /* returns either __metatable field (if present) or metatable */
+ luaL_checkany(L, 1);
+ if (!lua_getmetatable(L, 1)) {
+ lua_pushnil(L);
+ return 1; /* no metatable */
+ }
+ luaL_getmetafield(L, 1, "__metatable");
+ return 1; /* returns either __metatable field (if present) or metatable */
}
static int luaB_setmetatable (lua_State *L) {
- int t = lua_type(L, 2);
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
- "nil or table expected");
- if (luaL_getmetafield(L, 1, "__metatable"))
- return luaL_error(L, "cannot change a protected metatable");
- lua_settop(L, 2);
- lua_setmetatable(L, 1);
- return 1;
+ int t = lua_type(L, 2);
+ luaL_checktype(L, 1, LUA_TTABLE);
+ luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
+ "nil or table expected");
+ if (luaL_getmetafield(L, 1, "__metatable"))
+ return luaL_error(L, "cannot change a protected metatable");
+ lua_settop(L, 2);
+ lua_setmetatable(L, 1);
+ return 1;
}
static int luaB_rawequal (lua_State *L) {
- luaL_checkany(L, 1);
- luaL_checkany(L, 2);
- lua_pushboolean(L, lua_rawequal(L, 1, 2));
- return 1;
+ luaL_checkany(L, 1);
+ luaL_checkany(L, 2);
+ lua_pushboolean(L, lua_rawequal(L, 1, 2));
+ return 1;
}
static int luaB_rawlen (lua_State *L) {
- int t = lua_type(L, 1);
- luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
- "table or string expected");
- lua_pushinteger(L, lua_rawlen(L, 1));
- return 1;
+ int t = lua_type(L, 1);
+ luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
+ "table or string expected");
+ lua_pushinteger(L, lua_rawlen(L, 1));
+ return 1;
}
static int luaB_rawget (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_checkany(L, 2);
- lua_settop(L, 2);
- lua_rawget(L, 1);
- return 1;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ luaL_checkany(L, 2);
+ lua_settop(L, 2);
+ lua_rawget(L, 1);
+ return 1;
}
static int luaB_rawset (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- luaL_checkany(L, 2);
- luaL_checkany(L, 3);
- lua_settop(L, 3);
- lua_rawset(L, 1);
- return 1;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ luaL_checkany(L, 2);
+ luaL_checkany(L, 3);
+ lua_settop(L, 3);
+ lua_rawset(L, 1);
+ return 1;
}
static int luaB_collectgarbage (lua_State *L) {
- static const char *const opts[] = {"stop", "restart", "collect",
- "count", "step", "setpause", "setstepmul",
- "setmajorinc", "isrunning", "generational", "incremental", NULL};
- static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
- LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
- LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
- int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
- int ex = luaL_optint(L, 2, 0);
- int res = lua_gc(L, o, ex);
- switch (o) {
- case LUA_GCCOUNT: {
- int b = lua_gc(L, LUA_GCCOUNTB, 0);
- lua_pushnumber(L, res + ((lua_Number)b/1024));
- lua_pushinteger(L, b);
- return 2;
- }
- case LUA_GCSTEP: case LUA_GCISRUNNING: {
- lua_pushboolean(L, res);
- return 1;
- }
- default: {
- lua_pushinteger(L, res);
- return 1;
- }
- }
+ static const char *const opts[] = {"stop", "restart", "collect",
+ "count", "step", "setpause", "setstepmul",
+ "setmajorinc", "isrunning", "generational", "incremental", NULL};
+ static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
+ LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
+ LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
+ int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
+ int ex = luaL_optint(L, 2, 0);
+ int res = lua_gc(L, o, ex);
+ switch (o) {
+ case LUA_GCCOUNT: {
+ int b = lua_gc(L, LUA_GCCOUNTB, 0);
+ lua_pushnumber(L, res + ((lua_Number)b/1024));
+ lua_pushinteger(L, b);
+ return 2;
+ }
+ case LUA_GCSTEP: case LUA_GCISRUNNING: {
+ lua_pushboolean(L, res);
+ return 1;
+ }
+ default: {
+ lua_pushinteger(L, res);
+ return 1;
+ }
+ }
}
static int luaB_type (lua_State *L) {
- luaL_checkany(L, 1);
- lua_pushstring(L, luaL_typename(L, 1));
- return 1;
+ luaL_checkany(L, 1);
+ lua_pushstring(L, luaL_typename(L, 1));
+ return 1;
}
static int pairsmeta (lua_State *L, const char *method, int iszero,
- lua_CFunction iter) {
- if (!luaL_getmetafield(L, 1, method)) { /* no metamethod? */
- luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */
- lua_pushcfunction(L, iter); /* will return generator, */
- lua_pushvalue(L, 1); /* state, */
- if (iszero) lua_pushinteger(L, 0); /* and initial value */
- else lua_pushnil(L);
- }
- else {
- lua_pushvalue(L, 1); /* argument 'self' to metamethod */
- lua_call(L, 1, 3); /* get 3 values from metamethod */
- }
- return 3;
+ lua_CFunction iter) {
+ if (!luaL_getmetafield(L, 1, method)) { /* no metamethod? */
+ luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */
+ lua_pushcfunction(L, iter); /* will return generator, */
+ lua_pushvalue(L, 1); /* state, */
+ if (iszero) lua_pushinteger(L, 0); /* and initial value */
+ else lua_pushnil(L);
+ }
+ else {
+ lua_pushvalue(L, 1); /* argument 'self' to metamethod */
+ lua_call(L, 1, 3); /* get 3 values from metamethod */
+ }
+ return 3;
}
static int luaB_next (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_settop(L, 2); /* create a 2nd argument if there isn't one */
- if (lua_next(L, 1))
- return 2;
- else {
- lua_pushnil(L);
- return 1;
- }
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_settop(L, 2); /* create a 2nd argument if there isn't one */
+ if (lua_next(L, 1))
+ return 2;
+ else {
+ lua_pushnil(L);
+ return 1;
+ }
}
static int luaB_pairs (lua_State *L) {
- return pairsmeta(L, "__pairs", 0, luaB_next);
+ return pairsmeta(L, "__pairs", 0, luaB_next);
}
static int ipairsaux (lua_State *L) {
- int i = luaL_checkint(L, 2);
- luaL_checktype(L, 1, LUA_TTABLE);
- i++; /* next value */
- lua_pushinteger(L, i);
- lua_rawgeti(L, 1, i);
- return (lua_isnil(L, -1)) ? 1 : 2;
+ int i = luaL_checkint(L, 2);
+ luaL_checktype(L, 1, LUA_TTABLE);
+ i++; /* next value */
+ lua_pushinteger(L, i);
+ lua_rawgeti(L, 1, i);
+ return (lua_isnil(L, -1)) ? 1 : 2;
}
static int luaB_ipairs (lua_State *L) {
- return pairsmeta(L, "__ipairs", 1, ipairsaux);
+ return pairsmeta(L, "__ipairs", 1, ipairsaux);
}
static int load_aux (lua_State *L, int status, int envidx) {
- if (status == LUA_OK) {
- if (envidx != 0) { /* 'env' parameter? */
- lua_pushvalue(L, envidx); /* environment for loaded function */
- if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
- lua_pop(L, 1); /* remove 'env' if not used by previous call */
- }
- return 1;
- }
- else { /* error (message is on top of the stack) */
- lua_pushnil(L);
- lua_insert(L, -2); /* put before error message */
- return 2; /* return nil plus error message */
- }
+ if (status == LUA_OK) {
+ if (envidx != 0) { /* 'env' parameter? */
+ lua_pushvalue(L, envidx); /* environment for loaded function */
+ if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
+ lua_pop(L, 1); /* remove 'env' if not used by previous call */
+ }
+ return 1;
+ }
+ else { /* error (message is on top of the stack) */
+ lua_pushnil(L);
+ lua_insert(L, -2); /* put before error message */
+ return 2; /* return nil plus error message */
+ }
}
static int luaB_loadfile (lua_State *L) {
- const char *fname = luaL_optstring(L, 1, NULL);
- const char *mode = luaL_optstring(L, 2, NULL);
- int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
- int status = luaL_loadfilex(L, fname, mode);
- return load_aux(L, status, env);
+ const char *fname = luaL_optstring(L, 1, NULL);
+ const char *mode = luaL_optstring(L, 2, NULL);
+ int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
+ int status = luaL_loadfilex(L, fname, mode);
+ return load_aux(L, status, env);
}
@@ -280,7 +280,7 @@ static int luaB_loadfile (lua_State *L) {
** string to avoid it being collected while parsed. 'load' has four
** optional arguments (chunk, source name, mode, and environment).
*/
-#define RESERVEDSLOT 5
+#define RESERVEDSLOT 5
/*
@@ -290,169 +290,168 @@ static int luaB_loadfile (lua_State *L) {
** reserved slot inside the stack.
*/
static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
- (void)(ud); /* not used */
- luaL_checkstack(L, 2, "too many nested functions");
- lua_pushvalue(L, 1); /* get function */
- lua_call(L, 0, 1); /* call it */
- if (lua_isnil(L, -1)) {
- lua_pop(L, 1); /* pop result */
- *size = 0;
- return NULL;
- }
- else if (!lua_isstring(L, -1))
- luaL_error(L, "reader function must return a string");
- lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
- return lua_tolstring(L, RESERVEDSLOT, size);
+ (void)(ud); /* not used */
+ luaL_checkstack(L, 2, "too many nested functions");
+ lua_pushvalue(L, 1); /* get function */
+ lua_call(L, 0, 1); /* call it */
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 1); /* pop result */
+ *size = 0;
+ return NULL;
+ }
+ else if (!lua_isstring(L, -1))
+ luaL_error(L, "reader function must return a string");
+ lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
+ return lua_tolstring(L, RESERVEDSLOT, size);
}
static int luaB_load (lua_State *L) {
- int status;
- size_t l;
- const char *s = lua_tolstring(L, 1, &l);
- const char *mode = luaL_optstring(L, 3, "bt");
- int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
- if (s != NULL) { /* loading a string? */
- const char *chunkname = luaL_optstring(L, 2, s);
- status = luaL_loadbufferx(L, s, l, chunkname, mode);
- }
- else { /* loading from a reader function */
- const char *chunkname = luaL_optstring(L, 2, "=(load)");
- luaL_checktype(L, 1, LUA_TFUNCTION);
- lua_settop(L, RESERVEDSLOT); /* create reserved slot */
- status = lua_load(L, generic_reader, NULL, chunkname, mode);
- }
- return load_aux(L, status, env);
+ int status;
+ size_t l;
+ const char *s = lua_tolstring(L, 1, &l);
+ const char *mode = luaL_optstring(L, 3, "bt");
+ int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
+ if (s != NULL) { /* loading a string? */
+ const char *chunkname = luaL_optstring(L, 2, s);
+ status = luaL_loadbufferx(L, s, l, chunkname, mode);
+ }
+ else { /* loading from a reader function */
+ const char *chunkname = luaL_optstring(L, 2, "=(load)");
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+ lua_settop(L, RESERVEDSLOT); /* create reserved slot */
+ status = lua_load(L, generic_reader, NULL, chunkname, mode);
+ }
+ return load_aux(L, status, env);
}
/* }====================================================== */
static int dofilecont (lua_State *L) {
- return lua_gettop(L) - 1;
+ return lua_gettop(L) - 1;
}
static int luaB_dofile (lua_State *L) {
- const char *fname = luaL_optstring(L, 1, NULL);
- lua_settop(L, 1);
- if (luaL_loadfile(L, fname) != LUA_OK)
- return lua_error(L);
- lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
- return dofilecont(L);
+ const char *fname = luaL_optstring(L, 1, NULL);
+ lua_settop(L, 1);
+ if (luaL_loadfile(L, fname) != LUA_OK)
+ return lua_error(L);
+ lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
+ return dofilecont(L);
}
static int luaB_assert (lua_State *L) {
- if (!lua_toboolean(L, 1))
- return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
- return lua_gettop(L);
+ if (!lua_toboolean(L, 1))
+ return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
+ return lua_gettop(L);
}
static int luaB_select (lua_State *L) {
- int n = lua_gettop(L);
- if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
- lua_pushinteger(L, n-1);
- return 1;
- }
- else {
- int i = luaL_checkint(L, 1);
- if (i < 0) i = n + i;
- else if (i > n) i = n;
- luaL_argcheck(L, 1 <= i, 1, "index out of range");
- return n - i;
- }
+ int n = lua_gettop(L);
+ if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
+ lua_pushinteger(L, n-1);
+ return 1;
+ }
+ else {
+ int i = luaL_checkint(L, 1);
+ if (i < 0) i = n + i;
+ else if (i > n) i = n;
+ luaL_argcheck(L, 1 <= i, 1, "index out of range");
+ return n - i;
+ }
}
static int finishpcall (lua_State *L, int status) {
- if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */
- lua_settop(L, 0); /* create space for return values */
- lua_pushboolean(L, 0);
- lua_pushstring(L, "stack overflow");
- return 2; /* return false, msg */
- }
- lua_pushboolean(L, status); /* first result (status) */
- lua_replace(L, 1); /* put first result in first slot */
- return lua_gettop(L);
+ if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */
+ lua_settop(L, 0); /* create space for return values */
+ lua_pushboolean(L, 0);
+ lua_pushstring(L, "stack overflow");
+ return 2; /* return false, msg */
+ }
+ lua_pushboolean(L, status); /* first result (status) */
+ lua_replace(L, 1); /* put first result in first slot */
+ return lua_gettop(L);
}
static int pcallcont (lua_State *L) {
- int status = lua_getctx(L, NULL);
- return finishpcall(L, (status == LUA_YIELD));
+ int status = lua_getctx(L, NULL);
+ return finishpcall(L, (status == LUA_YIELD));
}
static int luaB_pcall (lua_State *L) {
- int status;
- luaL_checkany(L, 1);
- lua_pushnil(L);
- lua_insert(L, 1); /* create space for status result */
- status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);
- return finishpcall(L, (status == LUA_OK));
+ int status;
+ luaL_checkany(L, 1);
+ lua_pushnil(L);
+ lua_insert(L, 1); /* create space for status result */
+ status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);
+ return finishpcall(L, (status == LUA_OK));
}
static int luaB_xpcall (lua_State *L) {
- int status;
- int n = lua_gettop(L);
- luaL_argcheck(L, n >= 2, 2, "value expected");
- lua_pushvalue(L, 1); /* exchange function... */
- lua_copy(L, 2, 1); /* ...and error handler */
- lua_replace(L, 2);
- status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);
- return finishpcall(L, (status == LUA_OK));
+ int status;
+ int n = lua_gettop(L);
+ luaL_argcheck(L, n >= 2, 2, "value expected");
+ lua_pushvalue(L, 1); /* exchange function... */
+ lua_copy(L, 2, 1); /* ...and error handler */
+ lua_replace(L, 2);
+ status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);
+ return finishpcall(L, (status == LUA_OK));
}
static int luaB_tostring (lua_State *L) {
- luaL_checkany(L, 1);
- luaL_tolstring(L, 1, NULL);
- return 1;
+ luaL_checkany(L, 1);
+ luaL_tolstring(L, 1, NULL);
+ return 1;
}
static const luaL_Reg base_funcs[] = {
- {"assert", luaB_assert},
- {"collectgarbage", luaB_collectgarbage},
- {"dofile", luaB_dofile},
- {"error", luaB_error},
- {"getmetatable", luaB_getmetatable},
- {"ipairs", luaB_ipairs},
- {"loadfile", luaB_loadfile},
- {"load", luaB_load},
+ {"assert", luaB_assert},
+ {"collectgarbage", luaB_collectgarbage},
+ {"dofile", luaB_dofile},
+ {"error", luaB_error},
+ {"getmetatable", luaB_getmetatable},
+ {"ipairs", luaB_ipairs},
+ {"loadfile", luaB_loadfile},
+ {"load", luaB_load},
#if defined(LUA_COMPAT_LOADSTRING)
- {"loadstring", luaB_load},
+ {"loadstring", luaB_load},
#endif
- {"next", luaB_next},
- {"pairs", luaB_pairs},
- {"pcall", luaB_pcall},
- {"print", luaB_print},
- {"rawequal", luaB_rawequal},
- {"rawlen", luaB_rawlen},
- {"rawget", luaB_rawget},
- {"rawset", luaB_rawset},
- {"select", luaB_select},
- {"setmetatable", luaB_setmetatable},
- {"tonumber", luaB_tonumber},
- {"tostring", luaB_tostring},
- {"type", luaB_type},
- {"xpcall", luaB_xpcall},
- {NULL, NULL}
+ {"next", luaB_next},
+ {"pairs", luaB_pairs},
+ {"pcall", luaB_pcall},
+ {"print", luaB_print},
+ {"rawequal", luaB_rawequal},
+ {"rawlen", luaB_rawlen},
+ {"rawget", luaB_rawget},
+ {"rawset", luaB_rawset},
+ {"select", luaB_select},
+ {"setmetatable", luaB_setmetatable},
+ {"tonumber", luaB_tonumber},
+ {"tostring", luaB_tostring},
+ {"type", luaB_type},
+ {"xpcall", luaB_xpcall},
+ {NULL, NULL}
};
LUAMOD_API int luaopen_base (lua_State *L) {
- /* set global _G */
- lua_pushglobaltable(L);
- lua_pushglobaltable(L);
- lua_setfield(L, -2, "_G");
- /* open lib into global table */
- luaL_setfuncs(L, base_funcs, 0);
- lua_pushliteral(L, LUA_VERSION);
- lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
- return 1;
+ /* set global _G */
+ lua_pushglobaltable(L);
+ lua_pushglobaltable(L);
+ lua_setfield(L, -2, "_G");
+ /* open lib into global table */
+ luaL_setfuncs(L, base_funcs, 0);
+ lua_pushliteral(L, LUA_VERSION);
+ lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
+ return 1;
}
-
diff --git a/src/lib/lua/lbitlib.c b/src/lib/lua/lbitlib.c
index 9637532e3d8..e7ffb051658 100644
--- a/src/lib/lua/lbitlib.c
+++ b/src/lib/lua/lbitlib.c
@@ -15,18 +15,18 @@
/* number of bits to consider in a number */
#if !defined(LUA_NBITS)
-#define LUA_NBITS 32
+#define LUA_NBITS 32
#endif
-#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))
+#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))
/* macro to trim extra bits */
-#define trim(x) ((x) & ALLONES)
+#define trim(x) ((x) & ALLONES)
/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */
-#define mask(n) (~((ALLONES << 1) << ((n) - 1)))
+#define mask(n) (~((ALLONES << 1) << ((n) - 1)))
typedef lua_Unsigned b_uint;
@@ -34,114 +34,114 @@ typedef lua_Unsigned b_uint;
static b_uint andaux (lua_State *L) {
- int i, n = lua_gettop(L);
- b_uint r = ~(b_uint)0;
- for (i = 1; i <= n; i++)
- r &= luaL_checkunsigned(L, i);
- return trim(r);
+ int i, n = lua_gettop(L);
+ b_uint r = ~(b_uint)0;
+ for (i = 1; i <= n; i++)
+ r &= luaL_checkunsigned(L, i);
+ return trim(r);
}
static int b_and (lua_State *L) {
- b_uint r = andaux(L);
- lua_pushunsigned(L, r);
- return 1;
+ b_uint r = andaux(L);
+ lua_pushunsigned(L, r);
+ return 1;
}
static int b_test (lua_State *L) {
- b_uint r = andaux(L);
- lua_pushboolean(L, r != 0);
- return 1;
+ b_uint r = andaux(L);
+ lua_pushboolean(L, r != 0);
+ return 1;
}
static int b_or (lua_State *L) {
- int i, n = lua_gettop(L);
- b_uint r = 0;
- for (i = 1; i <= n; i++)
- r |= luaL_checkunsigned(L, i);
- lua_pushunsigned(L, trim(r));
- return 1;
+ int i, n = lua_gettop(L);
+ b_uint r = 0;
+ for (i = 1; i <= n; i++)
+ r |= luaL_checkunsigned(L, i);
+ lua_pushunsigned(L, trim(r));
+ return 1;
}
static int b_xor (lua_State *L) {
- int i, n = lua_gettop(L);
- b_uint r = 0;
- for (i = 1; i <= n; i++)
- r ^= luaL_checkunsigned(L, i);
- lua_pushunsigned(L, trim(r));
- return 1;
+ int i, n = lua_gettop(L);
+ b_uint r = 0;
+ for (i = 1; i <= n; i++)
+ r ^= luaL_checkunsigned(L, i);
+ lua_pushunsigned(L, trim(r));
+ return 1;
}
static int b_not (lua_State *L) {
- b_uint r = ~luaL_checkunsigned(L, 1);
- lua_pushunsigned(L, trim(r));
- return 1;
+ b_uint r = ~luaL_checkunsigned(L, 1);
+ lua_pushunsigned(L, trim(r));
+ return 1;
}
static int b_shift (lua_State *L, b_uint r, int i) {
- if (i < 0) { /* shift right? */
- i = -i;
- r = trim(r);
- if (i >= LUA_NBITS) r = 0;
- else r >>= i;
- }
- else { /* shift left */
- if (i >= LUA_NBITS) r = 0;
- else r <<= i;
- r = trim(r);
- }
- lua_pushunsigned(L, r);
- return 1;
+ if (i < 0) { /* shift right? */
+ i = -i;
+ r = trim(r);
+ if (i >= LUA_NBITS) r = 0;
+ else r >>= i;
+ }
+ else { /* shift left */
+ if (i >= LUA_NBITS) r = 0;
+ else r <<= i;
+ r = trim(r);
+ }
+ lua_pushunsigned(L, r);
+ return 1;
}
static int b_lshift (lua_State *L) {
- return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2));
+ return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2));
}
static int b_rshift (lua_State *L) {
- return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2));
+ return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2));
}
static int b_arshift (lua_State *L) {
- b_uint r = luaL_checkunsigned(L, 1);
- int i = luaL_checkint(L, 2);
- if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1))))
- return b_shift(L, r, -i);
- else { /* arithmetic shift for 'negative' number */
- if (i >= LUA_NBITS) r = ALLONES;
- else
- r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */
- lua_pushunsigned(L, r);
- return 1;
- }
+ b_uint r = luaL_checkunsigned(L, 1);
+ int i = luaL_checkint(L, 2);
+ if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1))))
+ return b_shift(L, r, -i);
+ else { /* arithmetic shift for 'negative' number */
+ if (i >= LUA_NBITS) r = ALLONES;
+ else
+ r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */
+ lua_pushunsigned(L, r);
+ return 1;
+ }
}
static int b_rot (lua_State *L, int i) {
- b_uint r = luaL_checkunsigned(L, 1);
- i &= (LUA_NBITS - 1); /* i = i % NBITS */
- r = trim(r);
- r = (r << i) | (r >> (LUA_NBITS - i));
- lua_pushunsigned(L, trim(r));
- return 1;
+ b_uint r = luaL_checkunsigned(L, 1);
+ i &= (LUA_NBITS - 1); /* i = i % NBITS */
+ r = trim(r);
+ r = (r << i) | (r >> (LUA_NBITS - i));
+ lua_pushunsigned(L, trim(r));
+ return 1;
}
static int b_lrot (lua_State *L) {
- return b_rot(L, luaL_checkint(L, 2));
+ return b_rot(L, luaL_checkint(L, 2));
}
static int b_rrot (lua_State *L) {
- return b_rot(L, -luaL_checkint(L, 2));
+ return b_rot(L, -luaL_checkint(L, 2));
}
@@ -152,60 +152,59 @@ static int b_rrot (lua_State *L) {
** 'width' being used uninitialized.)
*/
static int fieldargs (lua_State *L, int farg, int *width) {
- int f = luaL_checkint(L, farg);
- int w = luaL_optint(L, farg + 1, 1);
- luaL_argcheck(L, 0 <= f, farg, "field cannot be negative");
- luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");
- if (f + w > LUA_NBITS)
- luaL_error(L, "trying to access non-existent bits");
- *width = w;
- return f;
+ int f = luaL_checkint(L, farg);
+ int w = luaL_optint(L, farg + 1, 1);
+ luaL_argcheck(L, 0 <= f, farg, "field cannot be negative");
+ luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");
+ if (f + w > LUA_NBITS)
+ luaL_error(L, "trying to access non-existent bits");
+ *width = w;
+ return f;
}
static int b_extract (lua_State *L) {
- int w;
- b_uint r = luaL_checkunsigned(L, 1);
- int f = fieldargs(L, 2, &w);
- r = (r >> f) & mask(w);
- lua_pushunsigned(L, r);
- return 1;
+ int w;
+ b_uint r = luaL_checkunsigned(L, 1);
+ int f = fieldargs(L, 2, &w);
+ r = (r >> f) & mask(w);
+ lua_pushunsigned(L, r);
+ return 1;
}
static int b_replace (lua_State *L) {
- int w;
- b_uint r = luaL_checkunsigned(L, 1);
- b_uint v = luaL_checkunsigned(L, 2);
- int f = fieldargs(L, 3, &w);
- int m = mask(w);
- v &= m; /* erase bits outside given width */
- r = (r & ~(m << f)) | (v << f);
- lua_pushunsigned(L, r);
- return 1;
+ int w;
+ b_uint r = luaL_checkunsigned(L, 1);
+ b_uint v = luaL_checkunsigned(L, 2);
+ int f = fieldargs(L, 3, &w);
+ int m = mask(w);
+ v &= m; /* erase bits outside given width */
+ r = (r & ~(m << f)) | (v << f);
+ lua_pushunsigned(L, r);
+ return 1;
}
static const luaL_Reg bitlib[] = {
- {"arshift", b_arshift},
- {"band", b_and},
- {"bnot", b_not},
- {"bor", b_or},
- {"bxor", b_xor},
- {"btest", b_test},
- {"extract", b_extract},
- {"lrotate", b_lrot},
- {"lshift", b_lshift},
- {"replace", b_replace},
- {"rrotate", b_rrot},
- {"rshift", b_rshift},
- {NULL, NULL}
+ {"arshift", b_arshift},
+ {"band", b_and},
+ {"bnot", b_not},
+ {"bor", b_or},
+ {"bxor", b_xor},
+ {"btest", b_test},
+ {"extract", b_extract},
+ {"lrotate", b_lrot},
+ {"lshift", b_lshift},
+ {"replace", b_replace},
+ {"rrotate", b_rrot},
+ {"rshift", b_rshift},
+ {NULL, NULL}
};
LUAMOD_API int luaopen_bit32 (lua_State *L) {
- luaL_newlib(L, bitlib);
- return 1;
+ luaL_newlib(L, bitlib);
+ return 1;
}
-
diff --git a/src/lib/lua/lcode.c b/src/lib/lua/lcode.c
index 56c26ac8aac..e1ab7369590 100644
--- a/src/lib/lua/lcode.c
+++ b/src/lib/lua/lcode.c
@@ -26,64 +26,64 @@
#include "lvm.h"
-#define hasjumps(e) ((e)->t != (e)->f)
+#define hasjumps(e) ((e)->t != (e)->f)
static int isnumeral(expdesc *e) {
- return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
+ return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
}
void luaK_nil (FuncState *fs, int from, int n) {
- Instruction *previous;
- int l = from + n - 1; /* last register to set nil */
- if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
- previous = &fs->f->code[fs->pc-1];
- if (GET_OPCODE(*previous) == OP_LOADNIL) {
- int pfrom = GETARG_A(*previous);
- int pl = pfrom + GETARG_B(*previous);
- if ((pfrom <= from && from <= pl + 1) ||
- (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
- if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
- if (pl > l) l = pl; /* l = max(l, pl) */
- SETARG_A(*previous, from);
- SETARG_B(*previous, l - from);
- return;
- }
- } /* else go through */
- }
- luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
+ Instruction *previous;
+ int l = from + n - 1; /* last register to set nil */
+ if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
+ previous = &fs->f->code[fs->pc-1];
+ if (GET_OPCODE(*previous) == OP_LOADNIL) {
+ int pfrom = GETARG_A(*previous);
+ int pl = pfrom + GETARG_B(*previous);
+ if ((pfrom <= from && from <= pl + 1) ||
+ (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
+ if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
+ if (pl > l) l = pl; /* l = max(l, pl) */
+ SETARG_A(*previous, from);
+ SETARG_B(*previous, l - from);
+ return;
+ }
+ } /* else go through */
+ }
+ luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
}
int luaK_jump (FuncState *fs) {
- int jpc = fs->jpc; /* save list of jumps to here */
- int j;
- fs->jpc = NO_JUMP;
- j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
- luaK_concat(fs, &j, jpc); /* keep them on hold */
- return j;
+ int jpc = fs->jpc; /* save list of jumps to here */
+ int j;
+ fs->jpc = NO_JUMP;
+ j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
+ luaK_concat(fs, &j, jpc); /* keep them on hold */
+ return j;
}
void luaK_ret (FuncState *fs, int first, int nret) {
- luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
+ luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
}
static int condjump (FuncState *fs, OpCode op, int A, int B, int C) {
- luaK_codeABC(fs, op, A, B, C);
- return luaK_jump(fs);
+ luaK_codeABC(fs, op, A, B, C);
+ return luaK_jump(fs);
}
static void fixjump (FuncState *fs, int pc, int dest) {
- Instruction *jmp = &fs->f->code[pc];
- int offset = dest-(pc+1);
- lua_assert(dest != NO_JUMP);
- if (abs(offset) > MAXARG_sBx)
- luaX_syntaxerror(fs->ls, "control structure too long");
- SETARG_sBx(*jmp, offset);
+ Instruction *jmp = &fs->f->code[pc];
+ int offset = dest-(pc+1);
+ lua_assert(dest != NO_JUMP);
+ if (abs(offset) > MAXARG_sBx)
+ luaX_syntaxerror(fs->ls, "control structure too long");
+ SETARG_sBx(*jmp, offset);
}
@@ -92,26 +92,26 @@ static void fixjump (FuncState *fs, int pc, int dest) {
** optimizations with consecutive instructions not in the same basic block).
*/
int luaK_getlabel (FuncState *fs) {
- fs->lasttarget = fs->pc;
- return fs->pc;
+ fs->lasttarget = fs->pc;
+ return fs->pc;
}
static int getjump (FuncState *fs, int pc) {
- int offset = GETARG_sBx(fs->f->code[pc]);
- if (offset == NO_JUMP) /* point to itself represents end of list */
- return NO_JUMP; /* end of list */
- else
- return (pc+1)+offset; /* turn offset into absolute position */
+ int offset = GETARG_sBx(fs->f->code[pc]);
+ if (offset == NO_JUMP) /* point to itself represents end of list */
+ return NO_JUMP; /* end of list */
+ else
+ return (pc+1)+offset; /* turn offset into absolute position */
}
static Instruction *getjumpcontrol (FuncState *fs, int pc) {
- Instruction *pi = &fs->f->code[pc];
- if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
- return pi-1;
- else
- return pi;
+ Instruction *pi = &fs->f->code[pc];
+ if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
+ return pi-1;
+ else
+ return pi;
}
@@ -120,762 +120,761 @@ static Instruction *getjumpcontrol (FuncState *fs, int pc) {
** (or produce an inverted value)
*/
static int need_value (FuncState *fs, int list) {
- for (; list != NO_JUMP; list = getjump(fs, list)) {
- Instruction i = *getjumpcontrol(fs, list);
- if (GET_OPCODE(i) != OP_TESTSET) return 1;
- }
- return 0; /* not found */
+ for (; list != NO_JUMP; list = getjump(fs, list)) {
+ Instruction i = *getjumpcontrol(fs, list);
+ if (GET_OPCODE(i) != OP_TESTSET) return 1;
+ }
+ return 0; /* not found */
}
static int patchtestreg (FuncState *fs, int node, int reg) {
- Instruction *i = getjumpcontrol(fs, node);
- if (GET_OPCODE(*i) != OP_TESTSET)
- return 0; /* cannot patch other instructions */
- if (reg != NO_REG && reg != GETARG_B(*i))
- SETARG_A(*i, reg);
- else /* no register to put value or register already has the value */
- *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
+ Instruction *i = getjumpcontrol(fs, node);
+ if (GET_OPCODE(*i) != OP_TESTSET)
+ return 0; /* cannot patch other instructions */
+ if (reg != NO_REG && reg != GETARG_B(*i))
+ SETARG_A(*i, reg);
+ else /* no register to put value or register already has the value */
+ *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
- return 1;
+ return 1;
}
static void removevalues (FuncState *fs, int list) {
- for (; list != NO_JUMP; list = getjump(fs, list))
- patchtestreg(fs, list, NO_REG);
+ for (; list != NO_JUMP; list = getjump(fs, list))
+ patchtestreg(fs, list, NO_REG);
}
static void patchlistaux (FuncState *fs, int list, int vtarget, int reg,
- int dtarget) {
- while (list != NO_JUMP) {
- int next = getjump(fs, list);
- if (patchtestreg(fs, list, reg))
- fixjump(fs, list, vtarget);
- else
- fixjump(fs, list, dtarget); /* jump to default target */
- list = next;
- }
+ int dtarget) {
+ while (list != NO_JUMP) {
+ int next = getjump(fs, list);
+ if (patchtestreg(fs, list, reg))
+ fixjump(fs, list, vtarget);
+ else
+ fixjump(fs, list, dtarget); /* jump to default target */
+ list = next;
+ }
}
static void dischargejpc (FuncState *fs) {
- patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
- fs->jpc = NO_JUMP;
+ patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
+ fs->jpc = NO_JUMP;
}
void luaK_patchlist (FuncState *fs, int list, int target) {
- if (target == fs->pc)
- luaK_patchtohere(fs, list);
- else {
- lua_assert(target < fs->pc);
- patchlistaux(fs, list, target, NO_REG, target);
- }
+ if (target == fs->pc)
+ luaK_patchtohere(fs, list);
+ else {
+ lua_assert(target < fs->pc);
+ patchlistaux(fs, list, target, NO_REG, target);
+ }
}
LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) {
- level++; /* argument is +1 to reserve 0 as non-op */
- while (list != NO_JUMP) {
- int next = getjump(fs, list);
- lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
- (GETARG_A(fs->f->code[list]) == 0 ||
- GETARG_A(fs->f->code[list]) >= level));
- SETARG_A(fs->f->code[list], level);
- list = next;
- }
+ level++; /* argument is +1 to reserve 0 as non-op */
+ while (list != NO_JUMP) {
+ int next = getjump(fs, list);
+ lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
+ (GETARG_A(fs->f->code[list]) == 0 ||
+ GETARG_A(fs->f->code[list]) >= level));
+ SETARG_A(fs->f->code[list], level);
+ list = next;
+ }
}
void luaK_patchtohere (FuncState *fs, int list) {
- luaK_getlabel(fs);
- luaK_concat(fs, &fs->jpc, list);
+ luaK_getlabel(fs);
+ luaK_concat(fs, &fs->jpc, list);
}
void luaK_concat (FuncState *fs, int *l1, int l2) {
- if (l2 == NO_JUMP) return;
- else if (*l1 == NO_JUMP)
- *l1 = l2;
- else {
- int list = *l1;
- int next;
- while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
- list = next;
- fixjump(fs, list, l2);
- }
+ if (l2 == NO_JUMP) return;
+ else if (*l1 == NO_JUMP)
+ *l1 = l2;
+ else {
+ int list = *l1;
+ int next;
+ while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
+ list = next;
+ fixjump(fs, list, l2);
+ }
}
static int luaK_code (FuncState *fs, Instruction i) {
- Proto *f = fs->f;
- dischargejpc(fs); /* `pc' will change */
- /* put new instruction in code array */
- luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
- MAX_INT, "opcodes");
- f->code[fs->pc] = i;
- /* save corresponding line information */
- luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
- MAX_INT, "opcodes");
- f->lineinfo[fs->pc] = fs->ls->lastline;
- return fs->pc++;
+ Proto *f = fs->f;
+ dischargejpc(fs); /* `pc' will change */
+ /* put new instruction in code array */
+ luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
+ MAX_INT, "opcodes");
+ f->code[fs->pc] = i;
+ /* save corresponding line information */
+ luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
+ MAX_INT, "opcodes");
+ f->lineinfo[fs->pc] = fs->ls->lastline;
+ return fs->pc++;
}
int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
- lua_assert(getOpMode(o) == iABC);
- lua_assert(getBMode(o) != OpArgN || b == 0);
- lua_assert(getCMode(o) != OpArgN || c == 0);
- lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);
- return luaK_code(fs, CREATE_ABC(o, a, b, c));
+ lua_assert(getOpMode(o) == iABC);
+ lua_assert(getBMode(o) != OpArgN || b == 0);
+ lua_assert(getCMode(o) != OpArgN || c == 0);
+ lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);
+ return luaK_code(fs, CREATE_ABC(o, a, b, c));
}
int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
- lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
- lua_assert(getCMode(o) == OpArgN);
- lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
- return luaK_code(fs, CREATE_ABx(o, a, bc));
+ lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
+ lua_assert(getCMode(o) == OpArgN);
+ lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
+ return luaK_code(fs, CREATE_ABx(o, a, bc));
}
static int codeextraarg (FuncState *fs, int a) {
- lua_assert(a <= MAXARG_Ax);
- return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
+ lua_assert(a <= MAXARG_Ax);
+ return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
}
int luaK_codek (FuncState *fs, int reg, int k) {
- if (k <= MAXARG_Bx)
- return luaK_codeABx(fs, OP_LOADK, reg, k);
- else {
- int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
- codeextraarg(fs, k);
- return p;
- }
+ if (k <= MAXARG_Bx)
+ return luaK_codeABx(fs, OP_LOADK, reg, k);
+ else {
+ int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
+ codeextraarg(fs, k);
+ return p;
+ }
}
void luaK_checkstack (FuncState *fs, int n) {
- int newstack = fs->freereg + n;
- if (newstack > fs->f->maxstacksize) {
- if (newstack >= MAXSTACK)
- luaX_syntaxerror(fs->ls, "function or expression too complex");
- fs->f->maxstacksize = cast_byte(newstack);
- }
+ int newstack = fs->freereg + n;
+ if (newstack > fs->f->maxstacksize) {
+ if (newstack >= MAXSTACK)
+ luaX_syntaxerror(fs->ls, "function or expression too complex");
+ fs->f->maxstacksize = cast_byte(newstack);
+ }
}
void luaK_reserveregs (FuncState *fs, int n) {
- luaK_checkstack(fs, n);
- fs->freereg += n;
+ luaK_checkstack(fs, n);
+ fs->freereg += n;
}
static void freereg (FuncState *fs, int reg) {
- if (!ISK(reg) && reg >= fs->nactvar) {
- fs->freereg--;
- lua_assert(reg == fs->freereg);
- }
+ if (!ISK(reg) && reg >= fs->nactvar) {
+ fs->freereg--;
+ lua_assert(reg == fs->freereg);
+ }
}
static void freeexp (FuncState *fs, expdesc *e) {
- if (e->k == VNONRELOC)
- freereg(fs, e->u.info);
+ if (e->k == VNONRELOC)
+ freereg(fs, e->u.info);
}
static int addk (FuncState *fs, TValue *key, TValue *v) {
- lua_State *L = fs->ls->L;
- TValue *idx = luaH_set(L, fs->h, key);
- Proto *f = fs->f;
- int k, oldsize;
- if (ttisnumber(idx)) {
- lua_Number n = nvalue(idx);
- lua_number2int(k, n);
- if (luaV_rawequalobj(&f->k[k], v))
- return k;
- /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
- go through and create a new entry for this value */
- }
- /* constant not found; create a new entry */
- oldsize = f->sizek;
- k = fs->nk;
- /* numerical value does not need GC barrier;
- table has no metatable, so it does not need to invalidate cache */
- setnvalue(idx, cast_num(k));
- luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
- while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
- setobj(L, &f->k[k], v);
- fs->nk++;
- luaC_barrier(L, f, v);
- return k;
+ lua_State *L = fs->ls->L;
+ TValue *idx = luaH_set(L, fs->h, key);
+ Proto *f = fs->f;
+ int k, oldsize;
+ if (ttisnumber(idx)) {
+ lua_Number n = nvalue(idx);
+ lua_number2int(k, n);
+ if (luaV_rawequalobj(&f->k[k], v))
+ return k;
+ /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
+ go through and create a new entry for this value */
+ }
+ /* constant not found; create a new entry */
+ oldsize = f->sizek;
+ k = fs->nk;
+ /* numerical value does not need GC barrier;
+ table has no metatable, so it does not need to invalidate cache */
+ setnvalue(idx, cast_num(k));
+ luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
+ while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
+ setobj(L, &f->k[k], v);
+ fs->nk++;
+ luaC_barrier(L, f, v);
+ return k;
}
int luaK_stringK (FuncState *fs, TString *s) {
- TValue o;
- setsvalue(fs->ls->L, &o, s);
- return addk(fs, &o, &o);
+ TValue o;
+ setsvalue(fs->ls->L, &o, s);
+ return addk(fs, &o, &o);
}
int luaK_numberK (FuncState *fs, lua_Number r) {
- int n;
- lua_State *L = fs->ls->L;
- TValue o;
- setnvalue(&o, r);
- if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */
- /* use raw representation as key to avoid numeric problems */
- setsvalue(L, L->top++, luaS_newlstr(L, (char *)&r, sizeof(r)));
- n = addk(fs, L->top - 1, &o);
- L->top--;
- }
- else
- n = addk(fs, &o, &o); /* regular case */
- return n;
+ int n;
+ lua_State *L = fs->ls->L;
+ TValue o;
+ setnvalue(&o, r);
+ if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */
+ /* use raw representation as key to avoid numeric problems */
+ setsvalue(L, L->top++, luaS_newlstr(L, (char *)&r, sizeof(r)));
+ n = addk(fs, L->top - 1, &o);
+ L->top--;
+ }
+ else
+ n = addk(fs, &o, &o); /* regular case */
+ return n;
}
static int boolK (FuncState *fs, int b) {
- TValue o;
- setbvalue(&o, b);
- return addk(fs, &o, &o);
+ TValue o;
+ setbvalue(&o, b);
+ return addk(fs, &o, &o);
}
static int nilK (FuncState *fs) {
- TValue k, v;
- setnilvalue(&v);
- /* cannot use nil as key; instead use table itself to represent nil */
- sethvalue(fs->ls->L, &k, fs->h);
- return addk(fs, &k, &v);
+ TValue k, v;
+ setnilvalue(&v);
+ /* cannot use nil as key; instead use table itself to represent nil */
+ sethvalue(fs->ls->L, &k, fs->h);
+ return addk(fs, &k, &v);
}
void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
- if (e->k == VCALL) { /* expression is an open function call? */
- SETARG_C(getcode(fs, e), nresults+1);
- }
- else if (e->k == VVARARG) {
- SETARG_B(getcode(fs, e), nresults+1);
- SETARG_A(getcode(fs, e), fs->freereg);
- luaK_reserveregs(fs, 1);
- }
+ if (e->k == VCALL) { /* expression is an open function call? */
+ SETARG_C(getcode(fs, e), nresults+1);
+ }
+ else if (e->k == VVARARG) {
+ SETARG_B(getcode(fs, e), nresults+1);
+ SETARG_A(getcode(fs, e), fs->freereg);
+ luaK_reserveregs(fs, 1);
+ }
}
void luaK_setoneret (FuncState *fs, expdesc *e) {
- if (e->k == VCALL) { /* expression is an open function call? */
- e->k = VNONRELOC;
- e->u.info = GETARG_A(getcode(fs, e));
- }
- else if (e->k == VVARARG) {
- SETARG_B(getcode(fs, e), 2);
- e->k = VRELOCABLE; /* can relocate its simple result */
- }
+ if (e->k == VCALL) { /* expression is an open function call? */
+ e->k = VNONRELOC;
+ e->u.info = GETARG_A(getcode(fs, e));
+ }
+ else if (e->k == VVARARG) {
+ SETARG_B(getcode(fs, e), 2);
+ e->k = VRELOCABLE; /* can relocate its simple result */
+ }
}
void luaK_dischargevars (FuncState *fs, expdesc *e) {
- switch (e->k) {
- case VLOCAL: {
- e->k = VNONRELOC;
- break;
- }
- case VUPVAL: {
- e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
- e->k = VRELOCABLE;
- break;
- }
- case VINDEXED: {
- OpCode op = OP_GETTABUP; /* assume 't' is in an upvalue */
- freereg(fs, e->u.ind.idx);
- if (e->u.ind.vt == VLOCAL) { /* 't' is in a register? */
- freereg(fs, e->u.ind.t);
- op = OP_GETTABLE;
- }
- e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);
- e->k = VRELOCABLE;
- break;
- }
- case VVARARG:
- case VCALL: {
- luaK_setoneret(fs, e);
- break;
- }
- default: break; /* there is one value available (somewhere) */
- }
+ switch (e->k) {
+ case VLOCAL: {
+ e->k = VNONRELOC;
+ break;
+ }
+ case VUPVAL: {
+ e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
+ e->k = VRELOCABLE;
+ break;
+ }
+ case VINDEXED: {
+ OpCode op = OP_GETTABUP; /* assume 't' is in an upvalue */
+ freereg(fs, e->u.ind.idx);
+ if (e->u.ind.vt == VLOCAL) { /* 't' is in a register? */
+ freereg(fs, e->u.ind.t);
+ op = OP_GETTABLE;
+ }
+ e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);
+ e->k = VRELOCABLE;
+ break;
+ }
+ case VVARARG:
+ case VCALL: {
+ luaK_setoneret(fs, e);
+ break;
+ }
+ default: break; /* there is one value available (somewhere) */
+ }
}
static int code_label (FuncState *fs, int A, int b, int jump) {
- luaK_getlabel(fs); /* those instructions may be jump targets */
- return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
+ luaK_getlabel(fs); /* those instructions may be jump targets */
+ return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
}
static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VNIL: {
- luaK_nil(fs, reg, 1);
- break;
- }
- case VFALSE: case VTRUE: {
- luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
- break;
- }
- case VK: {
- luaK_codek(fs, reg, e->u.info);
- break;
- }
- case VKNUM: {
- luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));
- break;
- }
- case VRELOCABLE: {
- Instruction *pc = &getcode(fs, e);
- SETARG_A(*pc, reg);
- break;
- }
- case VNONRELOC: {
- if (reg != e->u.info)
- luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
- break;
- }
- default: {
- lua_assert(e->k == VVOID || e->k == VJMP);
- return; /* nothing to do... */
- }
- }
- e->u.info = reg;
- e->k = VNONRELOC;
+ luaK_dischargevars(fs, e);
+ switch (e->k) {
+ case VNIL: {
+ luaK_nil(fs, reg, 1);
+ break;
+ }
+ case VFALSE: case VTRUE: {
+ luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
+ break;
+ }
+ case VK: {
+ luaK_codek(fs, reg, e->u.info);
+ break;
+ }
+ case VKNUM: {
+ luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));
+ break;
+ }
+ case VRELOCABLE: {
+ Instruction *pc = &getcode(fs, e);
+ SETARG_A(*pc, reg);
+ break;
+ }
+ case VNONRELOC: {
+ if (reg != e->u.info)
+ luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
+ break;
+ }
+ default: {
+ lua_assert(e->k == VVOID || e->k == VJMP);
+ return; /* nothing to do... */
+ }
+ }
+ e->u.info = reg;
+ e->k = VNONRELOC;
}
static void discharge2anyreg (FuncState *fs, expdesc *e) {
- if (e->k != VNONRELOC) {
- luaK_reserveregs(fs, 1);
- discharge2reg(fs, e, fs->freereg-1);
- }
+ if (e->k != VNONRELOC) {
+ luaK_reserveregs(fs, 1);
+ discharge2reg(fs, e, fs->freereg-1);
+ }
}
static void exp2reg (FuncState *fs, expdesc *e, int reg) {
- discharge2reg(fs, e, reg);
- if (e->k == VJMP)
- luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */
- if (hasjumps(e)) {
- int final; /* position after whole expression */
- int p_f = NO_JUMP; /* position of an eventual LOAD false */
- int p_t = NO_JUMP; /* position of an eventual LOAD true */
- if (need_value(fs, e->t) || need_value(fs, e->f)) {
- int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
- p_f = code_label(fs, reg, 0, 1);
- p_t = code_label(fs, reg, 1, 0);
- luaK_patchtohere(fs, fj);
- }
- final = luaK_getlabel(fs);
- patchlistaux(fs, e->f, final, reg, p_f);
- patchlistaux(fs, e->t, final, reg, p_t);
- }
- e->f = e->t = NO_JUMP;
- e->u.info = reg;
- e->k = VNONRELOC;
+ discharge2reg(fs, e, reg);
+ if (e->k == VJMP)
+ luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */
+ if (hasjumps(e)) {
+ int final; /* position after whole expression */
+ int p_f = NO_JUMP; /* position of an eventual LOAD false */
+ int p_t = NO_JUMP; /* position of an eventual LOAD true */
+ if (need_value(fs, e->t) || need_value(fs, e->f)) {
+ int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
+ p_f = code_label(fs, reg, 0, 1);
+ p_t = code_label(fs, reg, 1, 0);
+ luaK_patchtohere(fs, fj);
+ }
+ final = luaK_getlabel(fs);
+ patchlistaux(fs, e->f, final, reg, p_f);
+ patchlistaux(fs, e->t, final, reg, p_t);
+ }
+ e->f = e->t = NO_JUMP;
+ e->u.info = reg;
+ e->k = VNONRELOC;
}
void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
- luaK_dischargevars(fs, e);
- freeexp(fs, e);
- luaK_reserveregs(fs, 1);
- exp2reg(fs, e, fs->freereg - 1);
+ luaK_dischargevars(fs, e);
+ freeexp(fs, e);
+ luaK_reserveregs(fs, 1);
+ exp2reg(fs, e, fs->freereg - 1);
}
int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
- luaK_dischargevars(fs, e);
- if (e->k == VNONRELOC) {
- if (!hasjumps(e)) return e->u.info; /* exp is already in a register */
- if (e->u.info >= fs->nactvar) { /* reg. is not a local? */
- exp2reg(fs, e, e->u.info); /* put value on it */
- return e->u.info;
- }
- }
- luaK_exp2nextreg(fs, e); /* default */
- return e->u.info;
+ luaK_dischargevars(fs, e);
+ if (e->k == VNONRELOC) {
+ if (!hasjumps(e)) return e->u.info; /* exp is already in a register */
+ if (e->u.info >= fs->nactvar) { /* reg. is not a local? */
+ exp2reg(fs, e, e->u.info); /* put value on it */
+ return e->u.info;
+ }
+ }
+ luaK_exp2nextreg(fs, e); /* default */
+ return e->u.info;
}
void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
- if (e->k != VUPVAL || hasjumps(e))
- luaK_exp2anyreg(fs, e);
+ if (e->k != VUPVAL || hasjumps(e))
+ luaK_exp2anyreg(fs, e);
}
void luaK_exp2val (FuncState *fs, expdesc *e) {
- if (hasjumps(e))
- luaK_exp2anyreg(fs, e);
- else
- luaK_dischargevars(fs, e);
+ if (hasjumps(e))
+ luaK_exp2anyreg(fs, e);
+ else
+ luaK_dischargevars(fs, e);
}
int luaK_exp2RK (FuncState *fs, expdesc *e) {
- luaK_exp2val(fs, e);
- switch (e->k) {
- case VTRUE:
- case VFALSE:
- case VNIL: {
- if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */
- e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
- e->k = VK;
- return RKASK(e->u.info);
- }
- else break;
- }
- case VKNUM: {
- e->u.info = luaK_numberK(fs, e->u.nval);
- e->k = VK;
- /* go through */
- }
- case VK: {
- if (e->u.info <= MAXINDEXRK) /* constant fits in argC? */
- return RKASK(e->u.info);
- else break;
- }
- default: break;
- }
- /* not a constant in the right range: put it in a register */
- return luaK_exp2anyreg(fs, e);
+ luaK_exp2val(fs, e);
+ switch (e->k) {
+ case VTRUE:
+ case VFALSE:
+ case VNIL: {
+ if (fs->nk <= MAXINDEXRK) { /* constant fits in RK operand? */
+ e->u.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE));
+ e->k = VK;
+ return RKASK(e->u.info);
+ }
+ else break;
+ }
+ case VKNUM: {
+ e->u.info = luaK_numberK(fs, e->u.nval);
+ e->k = VK;
+ /* go through */
+ }
+ case VK: {
+ if (e->u.info <= MAXINDEXRK) /* constant fits in argC? */
+ return RKASK(e->u.info);
+ else break;
+ }
+ default: break;
+ }
+ /* not a constant in the right range: put it in a register */
+ return luaK_exp2anyreg(fs, e);
}
void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
- switch (var->k) {
- case VLOCAL: {
- freeexp(fs, ex);
- exp2reg(fs, ex, var->u.info);
- return;
- }
- case VUPVAL: {
- int e = luaK_exp2anyreg(fs, ex);
- luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
- break;
- }
- case VINDEXED: {
- OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
- int e = luaK_exp2RK(fs, ex);
- luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
- break;
- }
- default: {
- lua_assert(0); /* invalid var kind to store */
- break;
- }
- }
- freeexp(fs, ex);
+ switch (var->k) {
+ case VLOCAL: {
+ freeexp(fs, ex);
+ exp2reg(fs, ex, var->u.info);
+ return;
+ }
+ case VUPVAL: {
+ int e = luaK_exp2anyreg(fs, ex);
+ luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
+ break;
+ }
+ case VINDEXED: {
+ OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;
+ int e = luaK_exp2RK(fs, ex);
+ luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
+ break;
+ }
+ default: {
+ lua_assert(0); /* invalid var kind to store */
+ break;
+ }
+ }
+ freeexp(fs, ex);
}
void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
- int ereg;
- luaK_exp2anyreg(fs, e);
- ereg = e->u.info; /* register where 'e' was placed */
- freeexp(fs, e);
- e->u.info = fs->freereg; /* base register for op_self */
- e->k = VNONRELOC;
- luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
- luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
- freeexp(fs, key);
+ int ereg;
+ luaK_exp2anyreg(fs, e);
+ ereg = e->u.info; /* register where 'e' was placed */
+ freeexp(fs, e);
+ e->u.info = fs->freereg; /* base register for op_self */
+ e->k = VNONRELOC;
+ luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
+ luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
+ freeexp(fs, key);
}
static void invertjump (FuncState *fs, expdesc *e) {
- Instruction *pc = getjumpcontrol(fs, e->u.info);
- lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
- GET_OPCODE(*pc) != OP_TEST);
- SETARG_A(*pc, !(GETARG_A(*pc)));
+ Instruction *pc = getjumpcontrol(fs, e->u.info);
+ lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
+ GET_OPCODE(*pc) != OP_TEST);
+ SETARG_A(*pc, !(GETARG_A(*pc)));
}
static int jumponcond (FuncState *fs, expdesc *e, int cond) {
- if (e->k == VRELOCABLE) {
- Instruction ie = getcode(fs, e);
- if (GET_OPCODE(ie) == OP_NOT) {
- fs->pc--; /* remove previous OP_NOT */
- return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
- }
- /* else go through */
- }
- discharge2anyreg(fs, e);
- freeexp(fs, e);
- return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
+ if (e->k == VRELOCABLE) {
+ Instruction ie = getcode(fs, e);
+ if (GET_OPCODE(ie) == OP_NOT) {
+ fs->pc--; /* remove previous OP_NOT */
+ return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
+ }
+ /* else go through */
+ }
+ discharge2anyreg(fs, e);
+ freeexp(fs, e);
+ return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
}
void luaK_goiftrue (FuncState *fs, expdesc *e) {
- int pc; /* pc of last jump */
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VJMP: {
- invertjump(fs, e);
- pc = e->u.info;
- break;
- }
- case VK: case VKNUM: case VTRUE: {
- pc = NO_JUMP; /* always true; do nothing */
- break;
- }
- default: {
- pc = jumponcond(fs, e, 0);
- break;
- }
- }
- luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
- luaK_patchtohere(fs, e->t);
- e->t = NO_JUMP;
+ int pc; /* pc of last jump */
+ luaK_dischargevars(fs, e);
+ switch (e->k) {
+ case VJMP: {
+ invertjump(fs, e);
+ pc = e->u.info;
+ break;
+ }
+ case VK: case VKNUM: case VTRUE: {
+ pc = NO_JUMP; /* always true; do nothing */
+ break;
+ }
+ default: {
+ pc = jumponcond(fs, e, 0);
+ break;
+ }
+ }
+ luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
+ luaK_patchtohere(fs, e->t);
+ e->t = NO_JUMP;
}
void luaK_goiffalse (FuncState *fs, expdesc *e) {
- int pc; /* pc of last jump */
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VJMP: {
- pc = e->u.info;
- break;
- }
- case VNIL: case VFALSE: {
- pc = NO_JUMP; /* always false; do nothing */
- break;
- }
- default: {
- pc = jumponcond(fs, e, 1);
- break;
- }
- }
- luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
- luaK_patchtohere(fs, e->f);
- e->f = NO_JUMP;
+ int pc; /* pc of last jump */
+ luaK_dischargevars(fs, e);
+ switch (e->k) {
+ case VJMP: {
+ pc = e->u.info;
+ break;
+ }
+ case VNIL: case VFALSE: {
+ pc = NO_JUMP; /* always false; do nothing */
+ break;
+ }
+ default: {
+ pc = jumponcond(fs, e, 1);
+ break;
+ }
+ }
+ luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
+ luaK_patchtohere(fs, e->f);
+ e->f = NO_JUMP;
}
static void codenot (FuncState *fs, expdesc *e) {
- luaK_dischargevars(fs, e);
- switch (e->k) {
- case VNIL: case VFALSE: {
- e->k = VTRUE;
- break;
- }
- case VK: case VKNUM: case VTRUE: {
- e->k = VFALSE;
- break;
- }
- case VJMP: {
- invertjump(fs, e);
- break;
- }
- case VRELOCABLE:
- case VNONRELOC: {
- discharge2anyreg(fs, e);
- freeexp(fs, e);
- e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
- e->k = VRELOCABLE;
- break;
- }
- default: {
- lua_assert(0); /* cannot happen */
- break;
- }
- }
- /* interchange true and false lists */
- { int temp = e->f; e->f = e->t; e->t = temp; }
- removevalues(fs, e->f);
- removevalues(fs, e->t);
+ luaK_dischargevars(fs, e);
+ switch (e->k) {
+ case VNIL: case VFALSE: {
+ e->k = VTRUE;
+ break;
+ }
+ case VK: case VKNUM: case VTRUE: {
+ e->k = VFALSE;
+ break;
+ }
+ case VJMP: {
+ invertjump(fs, e);
+ break;
+ }
+ case VRELOCABLE:
+ case VNONRELOC: {
+ discharge2anyreg(fs, e);
+ freeexp(fs, e);
+ e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);
+ e->k = VRELOCABLE;
+ break;
+ }
+ default: {
+ lua_assert(0); /* cannot happen */
+ break;
+ }
+ }
+ /* interchange true and false lists */
+ { int temp = e->f; e->f = e->t; e->t = temp; }
+ removevalues(fs, e->f);
+ removevalues(fs, e->t);
}
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
- lua_assert(!hasjumps(t));
- t->u.ind.t = t->u.info;
- t->u.ind.idx = luaK_exp2RK(fs, k);
- t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL
- : check_exp(vkisinreg(t->k), VLOCAL);
- t->k = VINDEXED;
+ lua_assert(!hasjumps(t));
+ t->u.ind.t = t->u.info;
+ t->u.ind.idx = luaK_exp2RK(fs, k);
+ t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL
+ : check_exp(vkisinreg(t->k), VLOCAL);
+ t->k = VINDEXED;
}
static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
- lua_Number r;
- if (!isnumeral(e1) || !isnumeral(e2)) return 0;
- if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0)
- return 0; /* do not attempt to divide by 0 */
- r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval);
- e1->u.nval = r;
- return 1;
+ lua_Number r;
+ if (!isnumeral(e1) || !isnumeral(e2)) return 0;
+ if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0)
+ return 0; /* do not attempt to divide by 0 */
+ r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval);
+ e1->u.nval = r;
+ return 1;
}
static void codearith (FuncState *fs, OpCode op,
- expdesc *e1, expdesc *e2, int line) {
- if (constfolding(op, e1, e2))
- return;
- else {
- int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
- int o1 = luaK_exp2RK(fs, e1);
- if (o1 > o2) {
- freeexp(fs, e1);
- freeexp(fs, e2);
- }
- else {
- freeexp(fs, e2);
- freeexp(fs, e1);
- }
- e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);
- e1->k = VRELOCABLE;
- luaK_fixline(fs, line);
- }
+ expdesc *e1, expdesc *e2, int line) {
+ if (constfolding(op, e1, e2))
+ return;
+ else {
+ int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
+ int o1 = luaK_exp2RK(fs, e1);
+ if (o1 > o2) {
+ freeexp(fs, e1);
+ freeexp(fs, e2);
+ }
+ else {
+ freeexp(fs, e2);
+ freeexp(fs, e1);
+ }
+ e1->u.info = luaK_codeABC(fs, op, 0, o1, o2);
+ e1->k = VRELOCABLE;
+ luaK_fixline(fs, line);
+ }
}
static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,
- expdesc *e2) {
- int o1 = luaK_exp2RK(fs, e1);
- int o2 = luaK_exp2RK(fs, e2);
- freeexp(fs, e2);
- freeexp(fs, e1);
- if (cond == 0 && op != OP_EQ) {
- int temp; /* exchange args to replace by `<' or `<=' */
- temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
- cond = 1;
- }
- e1->u.info = condjump(fs, op, cond, o1, o2);
- e1->k = VJMP;
+ expdesc *e2) {
+ int o1 = luaK_exp2RK(fs, e1);
+ int o2 = luaK_exp2RK(fs, e2);
+ freeexp(fs, e2);
+ freeexp(fs, e1);
+ if (cond == 0 && op != OP_EQ) {
+ int temp; /* exchange args to replace by `<' or `<=' */
+ temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
+ cond = 1;
+ }
+ e1->u.info = condjump(fs, op, cond, o1, o2);
+ e1->k = VJMP;
}
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
- expdesc e2;
- e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
- switch (op) {
- case OPR_MINUS: {
- if (isnumeral(e)) /* minus constant? */
- e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */
- else {
- luaK_exp2anyreg(fs, e);
- codearith(fs, OP_UNM, e, &e2, line);
- }
- break;
- }
- case OPR_NOT: codenot(fs, e); break;
- case OPR_LEN: {
- luaK_exp2anyreg(fs, e); /* cannot operate on constants */
- codearith(fs, OP_LEN, e, &e2, line);
- break;
- }
- default: lua_assert(0);
- }
+ expdesc e2;
+ e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
+ switch (op) {
+ case OPR_MINUS: {
+ if (isnumeral(e)) /* minus constant? */
+ e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */
+ else {
+ luaK_exp2anyreg(fs, e);
+ codearith(fs, OP_UNM, e, &e2, line);
+ }
+ break;
+ }
+ case OPR_NOT: codenot(fs, e); break;
+ case OPR_LEN: {
+ luaK_exp2anyreg(fs, e); /* cannot operate on constants */
+ codearith(fs, OP_LEN, e, &e2, line);
+ break;
+ }
+ default: lua_assert(0);
+ }
}
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
- switch (op) {
- case OPR_AND: {
- luaK_goiftrue(fs, v);
- break;
- }
- case OPR_OR: {
- luaK_goiffalse(fs, v);
- break;
- }
- case OPR_CONCAT: {
- luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
- break;
- }
- case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
- case OPR_MOD: case OPR_POW: {
- if (!isnumeral(v)) luaK_exp2RK(fs, v);
- break;
- }
- default: {
- luaK_exp2RK(fs, v);
- break;
- }
- }
+ switch (op) {
+ case OPR_AND: {
+ luaK_goiftrue(fs, v);
+ break;
+ }
+ case OPR_OR: {
+ luaK_goiffalse(fs, v);
+ break;
+ }
+ case OPR_CONCAT: {
+ luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
+ break;
+ }
+ case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
+ case OPR_MOD: case OPR_POW: {
+ if (!isnumeral(v)) luaK_exp2RK(fs, v);
+ break;
+ }
+ default: {
+ luaK_exp2RK(fs, v);
+ break;
+ }
+ }
}
void luaK_posfix (FuncState *fs, BinOpr op,
- expdesc *e1, expdesc *e2, int line) {
- switch (op) {
- case OPR_AND: {
- lua_assert(e1->t == NO_JUMP); /* list must be closed */
- luaK_dischargevars(fs, e2);
- luaK_concat(fs, &e2->f, e1->f);
- *e1 = *e2;
- break;
- }
- case OPR_OR: {
- lua_assert(e1->f == NO_JUMP); /* list must be closed */
- luaK_dischargevars(fs, e2);
- luaK_concat(fs, &e2->t, e1->t);
- *e1 = *e2;
- break;
- }
- case OPR_CONCAT: {
- luaK_exp2val(fs, e2);
- if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
- lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);
- freeexp(fs, e1);
- SETARG_B(getcode(fs, e2), e1->u.info);
- e1->k = VRELOCABLE; e1->u.info = e2->u.info;
- }
- else {
- luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
- codearith(fs, OP_CONCAT, e1, e2, line);
- }
- break;
- }
- case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
- case OPR_MOD: case OPR_POW: {
- codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
- break;
- }
- case OPR_EQ: case OPR_LT: case OPR_LE: {
- codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
- break;
- }
- case OPR_NE: case OPR_GT: case OPR_GE: {
- codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
- break;
- }
- default: lua_assert(0);
- }
+ expdesc *e1, expdesc *e2, int line) {
+ switch (op) {
+ case OPR_AND: {
+ lua_assert(e1->t == NO_JUMP); /* list must be closed */
+ luaK_dischargevars(fs, e2);
+ luaK_concat(fs, &e2->f, e1->f);
+ *e1 = *e2;
+ break;
+ }
+ case OPR_OR: {
+ lua_assert(e1->f == NO_JUMP); /* list must be closed */
+ luaK_dischargevars(fs, e2);
+ luaK_concat(fs, &e2->t, e1->t);
+ *e1 = *e2;
+ break;
+ }
+ case OPR_CONCAT: {
+ luaK_exp2val(fs, e2);
+ if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
+ lua_assert(e1->u.info == GETARG_B(getcode(fs, e2))-1);
+ freeexp(fs, e1);
+ SETARG_B(getcode(fs, e2), e1->u.info);
+ e1->k = VRELOCABLE; e1->u.info = e2->u.info;
+ }
+ else {
+ luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
+ codearith(fs, OP_CONCAT, e1, e2, line);
+ }
+ break;
+ }
+ case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
+ case OPR_MOD: case OPR_POW: {
+ codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line);
+ break;
+ }
+ case OPR_EQ: case OPR_LT: case OPR_LE: {
+ codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
+ break;
+ }
+ case OPR_NE: case OPR_GT: case OPR_GE: {
+ codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
+ break;
+ }
+ default: lua_assert(0);
+ }
}
void luaK_fixline (FuncState *fs, int line) {
- fs->f->lineinfo[fs->pc - 1] = line;
+ fs->f->lineinfo[fs->pc - 1] = line;
}
void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
- int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
- int b = (tostore == LUA_MULTRET) ? 0 : tostore;
- lua_assert(tostore != 0);
- if (c <= MAXARG_C)
- luaK_codeABC(fs, OP_SETLIST, base, b, c);
- else if (c <= MAXARG_Ax) {
- luaK_codeABC(fs, OP_SETLIST, base, b, 0);
- codeextraarg(fs, c);
- }
- else
- luaX_syntaxerror(fs->ls, "constructor too long");
- fs->freereg = base + 1; /* free registers with list values */
+ int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
+ int b = (tostore == LUA_MULTRET) ? 0 : tostore;
+ lua_assert(tostore != 0);
+ if (c <= MAXARG_C)
+ luaK_codeABC(fs, OP_SETLIST, base, b, c);
+ else if (c <= MAXARG_Ax) {
+ luaK_codeABC(fs, OP_SETLIST, base, b, 0);
+ codeextraarg(fs, c);
+ }
+ else
+ luaX_syntaxerror(fs->ls, "constructor too long");
+ fs->freereg = base + 1; /* free registers with list values */
}
-
diff --git a/src/lib/lua/lcode.h b/src/lib/lua/lcode.h
index 5a1fa9feac6..53642550af0 100644
--- a/src/lib/lua/lcode.h
+++ b/src/lib/lua/lcode.h
@@ -24,25 +24,25 @@
** grep "ORDER OPR" if you change these enums (ORDER OP)
*/
typedef enum BinOpr {
- OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
- OPR_CONCAT,
- OPR_EQ, OPR_LT, OPR_LE,
- OPR_NE, OPR_GT, OPR_GE,
- OPR_AND, OPR_OR,
- OPR_NOBINOPR
+ OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
+ OPR_CONCAT,
+ OPR_EQ, OPR_LT, OPR_LE,
+ OPR_NE, OPR_GT, OPR_GE,
+ OPR_AND, OPR_OR,
+ OPR_NOBINOPR
} BinOpr;
typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
-#define getcode(fs,e) ((fs)->f->code[(e)->u.info])
+#define getcode(fs,e) ((fs)->f->code[(e)->u.info])
-#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
+#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
-#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
+#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
-#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
+#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
@@ -76,7 +76,7 @@ LUAI_FUNC int luaK_getlabel (FuncState *fs);
LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,
- expdesc *v2, int line);
+ expdesc *v2, int line);
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
diff --git a/src/lib/lua/lcorolib.c b/src/lib/lua/lcorolib.c
index 1326c8146c5..4db4723699d 100644
--- a/src/lib/lua/lcorolib.c
+++ b/src/lib/lua/lcorolib.c
@@ -18,138 +18,137 @@
static int auxresume (lua_State *L, lua_State *co, int narg) {
- int status;
- if (!lua_checkstack(co, narg)) {
- lua_pushliteral(L, "too many arguments to resume");
- return -1; /* error flag */
- }
- if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
- lua_pushliteral(L, "cannot resume dead coroutine");
- return -1; /* error flag */
- }
- lua_xmove(L, co, narg);
- status = lua_resume(co, L, narg);
- if (status == LUA_OK || status == LUA_YIELD) {
- int nres = lua_gettop(co);
- if (!lua_checkstack(L, nres + 1)) {
- lua_pop(co, nres); /* remove results anyway */
- lua_pushliteral(L, "too many results to resume");
- return -1; /* error flag */
- }
- lua_xmove(co, L, nres); /* move yielded values */
- return nres;
- }
- else {
- lua_xmove(co, L, 1); /* move error message */
- return -1; /* error flag */
- }
+ int status;
+ if (!lua_checkstack(co, narg)) {
+ lua_pushliteral(L, "too many arguments to resume");
+ return -1; /* error flag */
+ }
+ if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
+ lua_pushliteral(L, "cannot resume dead coroutine");
+ return -1; /* error flag */
+ }
+ lua_xmove(L, co, narg);
+ status = lua_resume(co, L, narg);
+ if (status == LUA_OK || status == LUA_YIELD) {
+ int nres = lua_gettop(co);
+ if (!lua_checkstack(L, nres + 1)) {
+ lua_pop(co, nres); /* remove results anyway */
+ lua_pushliteral(L, "too many results to resume");
+ return -1; /* error flag */
+ }
+ lua_xmove(co, L, nres); /* move yielded values */
+ return nres;
+ }
+ else {
+ lua_xmove(co, L, 1); /* move error message */
+ return -1; /* error flag */
+ }
}
static int luaB_coresume (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- int r;
- luaL_argcheck(L, co, 1, "coroutine expected");
- r = auxresume(L, co, lua_gettop(L) - 1);
- if (r < 0) {
- lua_pushboolean(L, 0);
- lua_insert(L, -2);
- return 2; /* return false + error message */
- }
- else {
- lua_pushboolean(L, 1);
- lua_insert(L, -(r + 1));
- return r + 1; /* return true + `resume' returns */
- }
+ lua_State *co = lua_tothread(L, 1);
+ int r;
+ luaL_argcheck(L, co, 1, "coroutine expected");
+ r = auxresume(L, co, lua_gettop(L) - 1);
+ if (r < 0) {
+ lua_pushboolean(L, 0);
+ lua_insert(L, -2);
+ return 2; /* return false + error message */
+ }
+ else {
+ lua_pushboolean(L, 1);
+ lua_insert(L, -(r + 1));
+ return r + 1; /* return true + `resume' returns */
+ }
}
static int luaB_auxwrap (lua_State *L) {
- lua_State *co = lua_tothread(L, lua_upvalueindex(1));
- int r = auxresume(L, co, lua_gettop(L));
- if (r < 0) {
- if (lua_isstring(L, -1)) { /* error object is a string? */
- luaL_where(L, 1); /* add extra info */
- lua_insert(L, -2);
- lua_concat(L, 2);
- }
- return lua_error(L); /* propagate error */
- }
- return r;
+ lua_State *co = lua_tothread(L, lua_upvalueindex(1));
+ int r = auxresume(L, co, lua_gettop(L));
+ if (r < 0) {
+ if (lua_isstring(L, -1)) { /* error object is a string? */
+ luaL_where(L, 1); /* add extra info */
+ lua_insert(L, -2);
+ lua_concat(L, 2);
+ }
+ return lua_error(L); /* propagate error */
+ }
+ return r;
}
static int luaB_cocreate (lua_State *L) {
- lua_State *NL;
- luaL_checktype(L, 1, LUA_TFUNCTION);
- NL = lua_newthread(L);
- lua_pushvalue(L, 1); /* move function to top */
- lua_xmove(L, NL, 1); /* move function from L to NL */
- return 1;
+ lua_State *NL;
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+ NL = lua_newthread(L);
+ lua_pushvalue(L, 1); /* move function to top */
+ lua_xmove(L, NL, 1); /* move function from L to NL */
+ return 1;
}
static int luaB_cowrap (lua_State *L) {
- luaB_cocreate(L);
- lua_pushcclosure(L, luaB_auxwrap, 1);
- return 1;
+ luaB_cocreate(L);
+ lua_pushcclosure(L, luaB_auxwrap, 1);
+ return 1;
}
static int luaB_yield (lua_State *L) {
- return lua_yield(L, lua_gettop(L));
+ return lua_yield(L, lua_gettop(L));
}
static int luaB_costatus (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- luaL_argcheck(L, co, 1, "coroutine expected");
- if (L == co) lua_pushliteral(L, "running");
- else {
- switch (lua_status(co)) {
- case LUA_YIELD:
- lua_pushliteral(L, "suspended");
- break;
- case LUA_OK: {
- lua_Debug ar;
- if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
- lua_pushliteral(L, "normal"); /* it is running */
- else if (lua_gettop(co) == 0)
- lua_pushliteral(L, "dead");
- else
- lua_pushliteral(L, "suspended"); /* initial state */
- break;
- }
- default: /* some error occurred */
- lua_pushliteral(L, "dead");
- break;
- }
- }
- return 1;
+ lua_State *co = lua_tothread(L, 1);
+ luaL_argcheck(L, co, 1, "coroutine expected");
+ if (L == co) lua_pushliteral(L, "running");
+ else {
+ switch (lua_status(co)) {
+ case LUA_YIELD:
+ lua_pushliteral(L, "suspended");
+ break;
+ case LUA_OK: {
+ lua_Debug ar;
+ if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
+ lua_pushliteral(L, "normal"); /* it is running */
+ else if (lua_gettop(co) == 0)
+ lua_pushliteral(L, "dead");
+ else
+ lua_pushliteral(L, "suspended"); /* initial state */
+ break;
+ }
+ default: /* some error occurred */
+ lua_pushliteral(L, "dead");
+ break;
+ }
+ }
+ return 1;
}
static int luaB_corunning (lua_State *L) {
- int ismain = lua_pushthread(L);
- lua_pushboolean(L, ismain);
- return 2;
+ int ismain = lua_pushthread(L);
+ lua_pushboolean(L, ismain);
+ return 2;
}
static const luaL_Reg co_funcs[] = {
- {"create", luaB_cocreate},
- {"resume", luaB_coresume},
- {"running", luaB_corunning},
- {"status", luaB_costatus},
- {"wrap", luaB_cowrap},
- {"yield", luaB_yield},
- {NULL, NULL}
+ {"create", luaB_cocreate},
+ {"resume", luaB_coresume},
+ {"running", luaB_corunning},
+ {"status", luaB_costatus},
+ {"wrap", luaB_cowrap},
+ {"yield", luaB_yield},
+ {NULL, NULL}
};
LUAMOD_API int luaopen_coroutine (lua_State *L) {
- luaL_newlib(L, co_funcs);
- return 1;
+ luaL_newlib(L, co_funcs);
+ return 1;
}
-
diff --git a/src/lib/lua/lctype.c b/src/lib/lua/lctype.c
index 55e433a5dd7..d58140af2aa 100644
--- a/src/lib/lua/lctype.c
+++ b/src/lib/lua/lctype.c
@@ -9,44 +9,44 @@
#include "lctype.h"
-#if !LUA_USE_CTYPE /* { */
+#if !LUA_USE_CTYPE /* { */
#include <limits.h>
LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
- 0x00, /* EOZ */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
- 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
- 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
- 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
- 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
- 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
- 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
- 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
- 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
- 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
- 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, /* EOZ */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
+ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
+ 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+ 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
+ 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+ 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
+ 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
+ 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
+ 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
-#endif /* } */
+#endif /* } */
diff --git a/src/lib/lua/lctype.h b/src/lib/lua/lctype.h
index 99c7d122376..da45b2f9a01 100644
--- a/src/lib/lua/lctype.h
+++ b/src/lib/lua/lctype.h
@@ -20,58 +20,58 @@
#if 'A' == 65 && '0' == 48
/* ASCII case: can use its own tables; faster and fixed */
-#define LUA_USE_CTYPE 0
+#define LUA_USE_CTYPE 0
#else
/* must use standard C ctype */
-#define LUA_USE_CTYPE 1
+#define LUA_USE_CTYPE 1
#endif
#endif
-#if !LUA_USE_CTYPE /* { */
+#if !LUA_USE_CTYPE /* { */
#include <limits.h>
#include "llimits.h"
-#define ALPHABIT 0
-#define DIGITBIT 1
-#define PRINTBIT 2
-#define SPACEBIT 3
-#define XDIGITBIT 4
+#define ALPHABIT 0
+#define DIGITBIT 1
+#define PRINTBIT 2
+#define SPACEBIT 3
+#define XDIGITBIT 4
-#define MASK(B) (1 << (B))
+#define MASK(B) (1 << (B))
/*
** add 1 to char to allow index -1 (EOZ)
*/
-#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
+#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
/*
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
*/
-#define lislalpha(c) testprop(c, MASK(ALPHABIT))
-#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
-#define lisdigit(c) testprop(c, MASK(DIGITBIT))
-#define lisspace(c) testprop(c, MASK(SPACEBIT))
-#define lisprint(c) testprop(c, MASK(PRINTBIT))
-#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
+#define lislalpha(c) testprop(c, MASK(ALPHABIT))
+#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
+#define lisdigit(c) testprop(c, MASK(DIGITBIT))
+#define lisspace(c) testprop(c, MASK(SPACEBIT))
+#define lisprint(c) testprop(c, MASK(PRINTBIT))
+#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
/*
** this 'ltolower' only works for alphabetic characters
*/
-#define ltolower(c) ((c) | ('A' ^ 'a'))
+#define ltolower(c) ((c) | ('A' ^ 'a'))
/* two more entries for 0 and -1 (EOZ) */
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
-#else /* }{ */
+#else /* }{ */
/*
** use standard C ctypes
@@ -80,16 +80,15 @@ LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
#include <ctype.h>
-#define lislalpha(c) (isalpha(c) || (c) == '_')
-#define lislalnum(c) (isalnum(c) || (c) == '_')
-#define lisdigit(c) (isdigit(c))
-#define lisspace(c) (isspace(c))
-#define lisprint(c) (isprint(c))
-#define lisxdigit(c) (isxdigit(c))
+#define lislalpha(c) (isalpha(c) || (c) == '_')
+#define lislalnum(c) (isalnum(c) || (c) == '_')
+#define lisdigit(c) (isdigit(c))
+#define lisspace(c) (isspace(c))
+#define lisprint(c) (isprint(c))
+#define lisxdigit(c) (isxdigit(c))
-#define ltolower(c) (tolower(c))
+#define ltolower(c) (tolower(c))
-#endif /* } */
+#endif /* } */
#endif
-
diff --git a/src/lib/lua/ldblib.c b/src/lib/lua/ldblib.c
index c0226945737..823eded017e 100644
--- a/src/lib/lua/ldblib.c
+++ b/src/lib/lua/ldblib.c
@@ -18,381 +18,380 @@
#include "lualib.h"
-#define HOOKKEY "_HKEY"
+#define HOOKKEY "_HKEY"
static int db_getregistry (lua_State *L) {
- lua_pushvalue(L, LUA_REGISTRYINDEX);
- return 1;
+ lua_pushvalue(L, LUA_REGISTRYINDEX);
+ return 1;
}
static int db_getmetatable (lua_State *L) {
- luaL_checkany(L, 1);
- if (!lua_getmetatable(L, 1)) {
- lua_pushnil(L); /* no metatable */
- }
- return 1;
+ luaL_checkany(L, 1);
+ if (!lua_getmetatable(L, 1)) {
+ lua_pushnil(L); /* no metatable */
+ }
+ return 1;
}
static int db_setmetatable (lua_State *L) {
- int t = lua_type(L, 2);
- luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
- "nil or table expected");
- lua_settop(L, 2);
- lua_setmetatable(L, 1);
- return 1; /* return 1st argument */
+ int t = lua_type(L, 2);
+ luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
+ "nil or table expected");
+ lua_settop(L, 2);
+ lua_setmetatable(L, 1);
+ return 1; /* return 1st argument */
}
static int db_getuservalue (lua_State *L) {
- if (lua_type(L, 1) != LUA_TUSERDATA)
- lua_pushnil(L);
- else
- lua_getuservalue(L, 1);
- return 1;
+ if (lua_type(L, 1) != LUA_TUSERDATA)
+ lua_pushnil(L);
+ else
+ lua_getuservalue(L, 1);
+ return 1;
}
static int db_setuservalue (lua_State *L) {
- if (lua_type(L, 1) == LUA_TLIGHTUSERDATA)
- luaL_argerror(L, 1, "full userdata expected, got light userdata");
- luaL_checktype(L, 1, LUA_TUSERDATA);
- if (!lua_isnoneornil(L, 2))
- luaL_checktype(L, 2, LUA_TTABLE);
- lua_settop(L, 2);
- lua_setuservalue(L, 1);
- return 1;
+ if (lua_type(L, 1) == LUA_TLIGHTUSERDATA)
+ luaL_argerror(L, 1, "full userdata expected, got light userdata");
+ luaL_checktype(L, 1, LUA_TUSERDATA);
+ if (!lua_isnoneornil(L, 2))
+ luaL_checktype(L, 2, LUA_TTABLE);
+ lua_settop(L, 2);
+ lua_setuservalue(L, 1);
+ return 1;
}
static void settabss (lua_State *L, const char *i, const char *v) {
- lua_pushstring(L, v);
- lua_setfield(L, -2, i);
+ lua_pushstring(L, v);
+ lua_setfield(L, -2, i);
}
static void settabsi (lua_State *L, const char *i, int v) {
- lua_pushinteger(L, v);
- lua_setfield(L, -2, i);
+ lua_pushinteger(L, v);
+ lua_setfield(L, -2, i);
}
static void settabsb (lua_State *L, const char *i, int v) {
- lua_pushboolean(L, v);
- lua_setfield(L, -2, i);
+ lua_pushboolean(L, v);
+ lua_setfield(L, -2, i);
}
static lua_State *getthread (lua_State *L, int *arg) {
- if (lua_isthread(L, 1)) {
- *arg = 1;
- return lua_tothread(L, 1);
- }
- else {
- *arg = 0;
- return L;
- }
+ if (lua_isthread(L, 1)) {
+ *arg = 1;
+ return lua_tothread(L, 1);
+ }
+ else {
+ *arg = 0;
+ return L;
+ }
}
static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
- if (L == L1) {
- lua_pushvalue(L, -2);
- lua_remove(L, -3);
- }
- else
- lua_xmove(L1, L, 1);
- lua_setfield(L, -2, fname);
+ if (L == L1) {
+ lua_pushvalue(L, -2);
+ lua_remove(L, -3);
+ }
+ else
+ lua_xmove(L1, L, 1);
+ lua_setfield(L, -2, fname);
}
static int db_getinfo (lua_State *L) {
- lua_Debug ar;
- int arg;
- lua_State *L1 = getthread(L, &arg);
- const char *options = luaL_optstring(L, arg+2, "flnStu");
- if (lua_isnumber(L, arg+1)) {
- if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
- lua_pushnil(L); /* level out of range */
- return 1;
- }
- }
- else if (lua_isfunction(L, arg+1)) {
- lua_pushfstring(L, ">%s", options);
- options = lua_tostring(L, -1);
- lua_pushvalue(L, arg+1);
- lua_xmove(L, L1, 1);
- }
- else
- return luaL_argerror(L, arg+1, "function or level expected");
- if (!lua_getinfo(L1, options, &ar))
- return luaL_argerror(L, arg+2, "invalid option");
- lua_createtable(L, 0, 2);
- if (strchr(options, 'S')) {
- settabss(L, "source", ar.source);
- settabss(L, "short_src", ar.short_src);
- settabsi(L, "linedefined", ar.linedefined);
- settabsi(L, "lastlinedefined", ar.lastlinedefined);
- settabss(L, "what", ar.what);
- }
- if (strchr(options, 'l'))
- settabsi(L, "currentline", ar.currentline);
- if (strchr(options, 'u')) {
- settabsi(L, "nups", ar.nups);
- settabsi(L, "nparams", ar.nparams);
- settabsb(L, "isvararg", ar.isvararg);
- }
- if (strchr(options, 'n')) {
- settabss(L, "name", ar.name);
- settabss(L, "namewhat", ar.namewhat);
- }
- if (strchr(options, 't'))
- settabsb(L, "istailcall", ar.istailcall);
- if (strchr(options, 'L'))
- treatstackoption(L, L1, "activelines");
- if (strchr(options, 'f'))
- treatstackoption(L, L1, "func");
- return 1; /* return table */
+ lua_Debug ar;
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ const char *options = luaL_optstring(L, arg+2, "flnStu");
+ if (lua_isnumber(L, arg+1)) {
+ if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
+ lua_pushnil(L); /* level out of range */
+ return 1;
+ }
+ }
+ else if (lua_isfunction(L, arg+1)) {
+ lua_pushfstring(L, ">%s", options);
+ options = lua_tostring(L, -1);
+ lua_pushvalue(L, arg+1);
+ lua_xmove(L, L1, 1);
+ }
+ else
+ return luaL_argerror(L, arg+1, "function or level expected");
+ if (!lua_getinfo(L1, options, &ar))
+ return luaL_argerror(L, arg+2, "invalid option");
+ lua_createtable(L, 0, 2);
+ if (strchr(options, 'S')) {
+ settabss(L, "source", ar.source);
+ settabss(L, "short_src", ar.short_src);
+ settabsi(L, "linedefined", ar.linedefined);
+ settabsi(L, "lastlinedefined", ar.lastlinedefined);
+ settabss(L, "what", ar.what);
+ }
+ if (strchr(options, 'l'))
+ settabsi(L, "currentline", ar.currentline);
+ if (strchr(options, 'u')) {
+ settabsi(L, "nups", ar.nups);
+ settabsi(L, "nparams", ar.nparams);
+ settabsb(L, "isvararg", ar.isvararg);
+ }
+ if (strchr(options, 'n')) {
+ settabss(L, "name", ar.name);
+ settabss(L, "namewhat", ar.namewhat);
+ }
+ if (strchr(options, 't'))
+ settabsb(L, "istailcall", ar.istailcall);
+ if (strchr(options, 'L'))
+ treatstackoption(L, L1, "activelines");
+ if (strchr(options, 'f'))
+ treatstackoption(L, L1, "func");
+ return 1; /* return table */
}
static int db_getlocal (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- lua_Debug ar;
- const char *name;
- int nvar = luaL_checkint(L, arg+2); /* local-variable index */
- if (lua_isfunction(L, arg + 1)) { /* function argument? */
- lua_pushvalue(L, arg + 1); /* push function */
- lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */
- return 1;
- }
- else { /* stack-level argument */
- if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
- return luaL_argerror(L, arg+1, "level out of range");
- name = lua_getlocal(L1, &ar, nvar);
- if (name) {
- lua_xmove(L1, L, 1); /* push local value */
- lua_pushstring(L, name); /* push name */
- lua_pushvalue(L, -2); /* re-order */
- return 2;
- }
- else {
- lua_pushnil(L); /* no name (nor value) */
- return 1;
- }
- }
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ lua_Debug ar;
+ const char *name;
+ int nvar = luaL_checkint(L, arg+2); /* local-variable index */
+ if (lua_isfunction(L, arg + 1)) { /* function argument? */
+ lua_pushvalue(L, arg + 1); /* push function */
+ lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */
+ return 1;
+ }
+ else { /* stack-level argument */
+ if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
+ return luaL_argerror(L, arg+1, "level out of range");
+ name = lua_getlocal(L1, &ar, nvar);
+ if (name) {
+ lua_xmove(L1, L, 1); /* push local value */
+ lua_pushstring(L, name); /* push name */
+ lua_pushvalue(L, -2); /* re-order */
+ return 2;
+ }
+ else {
+ lua_pushnil(L); /* no name (nor value) */
+ return 1;
+ }
+ }
}
static int db_setlocal (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- lua_Debug ar;
- if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
- return luaL_argerror(L, arg+1, "level out of range");
- luaL_checkany(L, arg+3);
- lua_settop(L, arg+3);
- lua_xmove(L, L1, 1);
- lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
- return 1;
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ lua_Debug ar;
+ if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
+ return luaL_argerror(L, arg+1, "level out of range");
+ luaL_checkany(L, arg+3);
+ lua_settop(L, arg+3);
+ lua_xmove(L, L1, 1);
+ lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
+ return 1;
}
static int auxupvalue (lua_State *L, int get) {
- const char *name;
- int n = luaL_checkint(L, 2);
- luaL_checktype(L, 1, LUA_TFUNCTION);
- name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
- if (name == NULL) return 0;
- lua_pushstring(L, name);
- lua_insert(L, -(get+1));
- return get + 1;
+ const char *name;
+ int n = luaL_checkint(L, 2);
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+ name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
+ if (name == NULL) return 0;
+ lua_pushstring(L, name);
+ lua_insert(L, -(get+1));
+ return get + 1;
}
static int db_getupvalue (lua_State *L) {
- return auxupvalue(L, 1);
+ return auxupvalue(L, 1);
}
static int db_setupvalue (lua_State *L) {
- luaL_checkany(L, 3);
- return auxupvalue(L, 0);
+ luaL_checkany(L, 3);
+ return auxupvalue(L, 0);
}
static int checkupval (lua_State *L, int argf, int argnup) {
- lua_Debug ar;
- int nup = luaL_checkint(L, argnup);
- luaL_checktype(L, argf, LUA_TFUNCTION);
- lua_pushvalue(L, argf);
- lua_getinfo(L, ">u", &ar);
- luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index");
- return nup;
+ lua_Debug ar;
+ int nup = luaL_checkint(L, argnup);
+ luaL_checktype(L, argf, LUA_TFUNCTION);
+ lua_pushvalue(L, argf);
+ lua_getinfo(L, ">u", &ar);
+ luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index");
+ return nup;
}
static int db_upvalueid (lua_State *L) {
- int n = checkupval(L, 1, 2);
- lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));
- return 1;
+ int n = checkupval(L, 1, 2);
+ lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));
+ return 1;
}
static int db_upvaluejoin (lua_State *L) {
- int n1 = checkupval(L, 1, 2);
- int n2 = checkupval(L, 3, 4);
- luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
- luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
- lua_upvaluejoin(L, 1, n1, 3, n2);
- return 0;
+ int n1 = checkupval(L, 1, 2);
+ int n2 = checkupval(L, 3, 4);
+ luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
+ luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
+ lua_upvaluejoin(L, 1, n1, 3, n2);
+ return 0;
}
-#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
+#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
static void hookf (lua_State *L, lua_Debug *ar) {
- static const char *const hooknames[] =
- {"call", "return", "line", "count", "tail call"};
- gethooktable(L);
- lua_pushthread(L);
- lua_rawget(L, -2);
- if (lua_isfunction(L, -1)) {
- lua_pushstring(L, hooknames[(int)ar->event]);
- if (ar->currentline >= 0)
- lua_pushinteger(L, ar->currentline);
- else lua_pushnil(L);
- lua_assert(lua_getinfo(L, "lS", ar));
- lua_call(L, 2, 0);
- }
+ static const char *const hooknames[] =
+ {"call", "return", "line", "count", "tail call"};
+ gethooktable(L);
+ lua_pushthread(L);
+ lua_rawget(L, -2);
+ if (lua_isfunction(L, -1)) {
+ lua_pushstring(L, hooknames[(int)ar->event]);
+ if (ar->currentline >= 0)
+ lua_pushinteger(L, ar->currentline);
+ else lua_pushnil(L);
+ lua_assert(lua_getinfo(L, "lS", ar));
+ lua_call(L, 2, 0);
+ }
}
static int makemask (const char *smask, int count) {
- int mask = 0;
- if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
- if (strchr(smask, 'r')) mask |= LUA_MASKRET;
- if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
- if (count > 0) mask |= LUA_MASKCOUNT;
- return mask;
+ int mask = 0;
+ if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
+ if (strchr(smask, 'r')) mask |= LUA_MASKRET;
+ if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
+ if (count > 0) mask |= LUA_MASKCOUNT;
+ return mask;
}
static char *unmakemask (int mask, char *smask) {
- int i = 0;
- if (mask & LUA_MASKCALL) smask[i++] = 'c';
- if (mask & LUA_MASKRET) smask[i++] = 'r';
- if (mask & LUA_MASKLINE) smask[i++] = 'l';
- smask[i] = '\0';
- return smask;
+ int i = 0;
+ if (mask & LUA_MASKCALL) smask[i++] = 'c';
+ if (mask & LUA_MASKRET) smask[i++] = 'r';
+ if (mask & LUA_MASKLINE) smask[i++] = 'l';
+ smask[i] = '\0';
+ return smask;
}
static int db_sethook (lua_State *L) {
- int arg, mask, count;
- lua_Hook func;
- lua_State *L1 = getthread(L, &arg);
- if (lua_isnoneornil(L, arg+1)) {
- lua_settop(L, arg+1);
- func = NULL; mask = 0; count = 0; /* turn off hooks */
- }
- else {
- const char *smask = luaL_checkstring(L, arg+2);
- luaL_checktype(L, arg+1, LUA_TFUNCTION);
- count = luaL_optint(L, arg+3, 0);
- func = hookf; mask = makemask(smask, count);
- }
- if (gethooktable(L) == 0) { /* creating hook table? */
- lua_pushstring(L, "k");
- lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
- lua_pushvalue(L, -1);
- lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
- }
- lua_pushthread(L1); lua_xmove(L1, L, 1);
- lua_pushvalue(L, arg+1);
- lua_rawset(L, -3); /* set new hook */
- lua_sethook(L1, func, mask, count); /* set hooks */
- return 0;
+ int arg, mask, count;
+ lua_Hook func;
+ lua_State *L1 = getthread(L, &arg);
+ if (lua_isnoneornil(L, arg+1)) {
+ lua_settop(L, arg+1);
+ func = NULL; mask = 0; count = 0; /* turn off hooks */
+ }
+ else {
+ const char *smask = luaL_checkstring(L, arg+2);
+ luaL_checktype(L, arg+1, LUA_TFUNCTION);
+ count = luaL_optint(L, arg+3, 0);
+ func = hookf; mask = makemask(smask, count);
+ }
+ if (gethooktable(L) == 0) { /* creating hook table? */
+ lua_pushstring(L, "k");
+ lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
+ lua_pushvalue(L, -1);
+ lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
+ }
+ lua_pushthread(L1); lua_xmove(L1, L, 1);
+ lua_pushvalue(L, arg+1);
+ lua_rawset(L, -3); /* set new hook */
+ lua_sethook(L1, func, mask, count); /* set hooks */
+ return 0;
}
static int db_gethook (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- char buff[5];
- int mask = lua_gethookmask(L1);
- lua_Hook hook = lua_gethook(L1);
- if (hook != NULL && hook != hookf) /* external hook? */
- lua_pushliteral(L, "external hook");
- else {
- gethooktable(L);
- lua_pushthread(L1); lua_xmove(L1, L, 1);
- lua_rawget(L, -2); /* get hook */
- lua_remove(L, -2); /* remove hook table */
- }
- lua_pushstring(L, unmakemask(mask, buff));
- lua_pushinteger(L, lua_gethookcount(L1));
- return 3;
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ char buff[5];
+ int mask = lua_gethookmask(L1);
+ lua_Hook hook = lua_gethook(L1);
+ if (hook != NULL && hook != hookf) /* external hook? */
+ lua_pushliteral(L, "external hook");
+ else {
+ gethooktable(L);
+ lua_pushthread(L1); lua_xmove(L1, L, 1);
+ lua_rawget(L, -2); /* get hook */
+ lua_remove(L, -2); /* remove hook table */
+ }
+ lua_pushstring(L, unmakemask(mask, buff));
+ lua_pushinteger(L, lua_gethookcount(L1));
+ return 3;
}
static int db_debug (lua_State *L) {
- for (;;) {
- char buffer[250];
- luai_writestringerror("%s", "lua_debug> ");
- if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
- strcmp(buffer, "cont\n") == 0)
- return 0;
- if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
- lua_pcall(L, 0, 0, 0))
- luai_writestringerror("%s\n", lua_tostring(L, -1));
- lua_settop(L, 0); /* remove eventual returns */
- }
+ for (;;) {
+ char buffer[250];
+ luai_writestringerror("%s", "lua_debug> ");
+ if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
+ strcmp(buffer, "cont\n") == 0)
+ return 0;
+ if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
+ lua_pcall(L, 0, 0, 0))
+ luai_writestringerror("%s\n", lua_tostring(L, -1));
+ lua_settop(L, 0); /* remove eventual returns */
+ }
}
static int db_traceback (lua_State *L) {
- int arg;
- lua_State *L1 = getthread(L, &arg);
- const char *msg = lua_tostring(L, arg + 1);
- if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
- lua_pushvalue(L, arg + 1); /* return it untouched */
- else {
- int level = luaL_optint(L, arg + 2, (L == L1) ? 1 : 0);
- luaL_traceback(L, L1, msg, level);
- }
- return 1;
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ const char *msg = lua_tostring(L, arg + 1);
+ if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
+ lua_pushvalue(L, arg + 1); /* return it untouched */
+ else {
+ int level = luaL_optint(L, arg + 2, (L == L1) ? 1 : 0);
+ luaL_traceback(L, L1, msg, level);
+ }
+ return 1;
}
static const luaL_Reg dblib[] = {
- {"debug", db_debug},
- {"getuservalue", db_getuservalue},
- {"gethook", db_gethook},
- {"getinfo", db_getinfo},
- {"getlocal", db_getlocal},
- {"getregistry", db_getregistry},
- {"getmetatable", db_getmetatable},
- {"getupvalue", db_getupvalue},
- {"upvaluejoin", db_upvaluejoin},
- {"upvalueid", db_upvalueid},
- {"setuservalue", db_setuservalue},
- {"sethook", db_sethook},
- {"setlocal", db_setlocal},
- {"setmetatable", db_setmetatable},
- {"setupvalue", db_setupvalue},
- {"traceback", db_traceback},
- {NULL, NULL}
+ {"debug", db_debug},
+ {"getuservalue", db_getuservalue},
+ {"gethook", db_gethook},
+ {"getinfo", db_getinfo},
+ {"getlocal", db_getlocal},
+ {"getregistry", db_getregistry},
+ {"getmetatable", db_getmetatable},
+ {"getupvalue", db_getupvalue},
+ {"upvaluejoin", db_upvaluejoin},
+ {"upvalueid", db_upvalueid},
+ {"setuservalue", db_setuservalue},
+ {"sethook", db_sethook},
+ {"setlocal", db_setlocal},
+ {"setmetatable", db_setmetatable},
+ {"setupvalue", db_setupvalue},
+ {"traceback", db_traceback},
+ {NULL, NULL}
};
LUAMOD_API int luaopen_debug (lua_State *L) {
- luaL_newlib(L, dblib);
- return 1;
+ luaL_newlib(L, dblib);
+ return 1;
}
-
diff --git a/src/lib/lua/ldebug.c b/src/lib/lua/ldebug.c
index 7e04f9d09f8..8db970c2ac3 100644
--- a/src/lib/lua/ldebug.c
+++ b/src/lib/lua/ldebug.c
@@ -30,20 +30,20 @@
-#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)
+#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
static int currentpc (CallInfo *ci) {
- lua_assert(isLua(ci));
- return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
+ lua_assert(isLua(ci));
+ return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
}
static int currentline (CallInfo *ci) {
- return getfuncline(ci_func(ci)->p, currentpc(ci));
+ return getfuncline(ci_func(ci)->p, currentpc(ci));
}
@@ -51,246 +51,246 @@ static int currentline (CallInfo *ci) {
** this function can be called asynchronous (e.g. during a signal)
*/
LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
- if (func == NULL || mask == 0) { /* turn off hooks? */
- mask = 0;
- func = NULL;
- }
- if (isLua(L->ci))
- L->oldpc = L->ci->u.l.savedpc;
- L->hook = func;
- L->basehookcount = count;
- resethookcount(L);
- L->hookmask = cast_byte(mask);
- return 1;
+ if (func == NULL || mask == 0) { /* turn off hooks? */
+ mask = 0;
+ func = NULL;
+ }
+ if (isLua(L->ci))
+ L->oldpc = L->ci->u.l.savedpc;
+ L->hook = func;
+ L->basehookcount = count;
+ resethookcount(L);
+ L->hookmask = cast_byte(mask);
+ return 1;
}
LUA_API lua_Hook lua_gethook (lua_State *L) {
- return L->hook;
+ return L->hook;
}
LUA_API int lua_gethookmask (lua_State *L) {
- return L->hookmask;
+ return L->hookmask;
}
LUA_API int lua_gethookcount (lua_State *L) {
- return L->basehookcount;
+ return L->basehookcount;
}
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
- int status;
- CallInfo *ci;
- if (level < 0) return 0; /* invalid (negative) level */
- lua_lock(L);
- for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)
- level--;
- if (level == 0 && ci != &L->base_ci) { /* level found? */
- status = 1;
- ar->i_ci = ci;
- }
- else status = 0; /* no such level */
- lua_unlock(L);
- return status;
+ int status;
+ CallInfo *ci;
+ if (level < 0) return 0; /* invalid (negative) level */
+ lua_lock(L);
+ for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)
+ level--;
+ if (level == 0 && ci != &L->base_ci) { /* level found? */
+ status = 1;
+ ar->i_ci = ci;
+ }
+ else status = 0; /* no such level */
+ lua_unlock(L);
+ return status;
}
static const char *upvalname (Proto *p, int uv) {
- TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
- if (s == NULL) return "?";
- else return getstr(s);
+ TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);
+ if (s == NULL) return "?";
+ else return getstr(s);
}
static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
- int nparams = clLvalue(ci->func)->p->numparams;
- if (n >= ci->u.l.base - ci->func - nparams)
- return NULL; /* no such vararg */
- else {
- *pos = ci->func + nparams + n;
- return "(*vararg)"; /* generic name for any vararg */
- }
+ int nparams = clLvalue(ci->func)->p->numparams;
+ if (n >= ci->u.l.base - ci->func - nparams)
+ return NULL; /* no such vararg */
+ else {
+ *pos = ci->func + nparams + n;
+ return "(*vararg)"; /* generic name for any vararg */
+ }
}
static const char *findlocal (lua_State *L, CallInfo *ci, int n,
- StkId *pos) {
- const char *name = NULL;
- StkId base;
- if (isLua(ci)) {
- if (n < 0) /* access to vararg values? */
- return findvararg(ci, -n, pos);
- else {
- base = ci->u.l.base;
- name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
- }
- }
- else
- base = ci->func + 1;
- if (name == NULL) { /* no 'standard' name? */
- StkId limit = (ci == L->ci) ? L->top : ci->next->func;
- if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
- name = "(*temporary)"; /* generic name for any valid slot */
- else
- return NULL; /* no name */
- }
- *pos = base + (n - 1);
- return name;
+ StkId *pos) {
+ const char *name = NULL;
+ StkId base;
+ if (isLua(ci)) {
+ if (n < 0) /* access to vararg values? */
+ return findvararg(ci, -n, pos);
+ else {
+ base = ci->u.l.base;
+ name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
+ }
+ }
+ else
+ base = ci->func + 1;
+ if (name == NULL) { /* no 'standard' name? */
+ StkId limit = (ci == L->ci) ? L->top : ci->next->func;
+ if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
+ name = "(*temporary)"; /* generic name for any valid slot */
+ else
+ return NULL; /* no name */
+ }
+ *pos = base + (n - 1);
+ return name;
}
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
- const char *name;
- lua_lock(L);
- if (ar == NULL) { /* information about non-active function? */
- if (!isLfunction(L->top - 1)) /* not a Lua function? */
- name = NULL;
- else /* consider live variables at function start (parameters) */
- name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
- }
- else { /* active function; get information through 'ar' */
- StkId pos = 0; /* to avoid warnings */
- name = findlocal(L, ar->i_ci, n, &pos);
- if (name) {
- setobj2s(L, L->top, pos);
- api_incr_top(L);
- }
- }
- lua_unlock(L);
- return name;
+ const char *name;
+ lua_lock(L);
+ if (ar == NULL) { /* information about non-active function? */
+ if (!isLfunction(L->top - 1)) /* not a Lua function? */
+ name = NULL;
+ else /* consider live variables at function start (parameters) */
+ name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
+ }
+ else { /* active function; get information through 'ar' */
+ StkId pos = 0; /* to avoid warnings */
+ name = findlocal(L, ar->i_ci, n, &pos);
+ if (name) {
+ setobj2s(L, L->top, pos);
+ api_incr_top(L);
+ }
+ }
+ lua_unlock(L);
+ return name;
}
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
- StkId pos = 0; /* to avoid warnings */
- const char *name = findlocal(L, ar->i_ci, n, &pos);
- lua_lock(L);
- if (name)
- setobjs2s(L, pos, L->top - 1);
- L->top--; /* pop value */
- lua_unlock(L);
- return name;
+ StkId pos = 0; /* to avoid warnings */
+ const char *name = findlocal(L, ar->i_ci, n, &pos);
+ lua_lock(L);
+ if (name)
+ setobjs2s(L, pos, L->top - 1);
+ L->top--; /* pop value */
+ lua_unlock(L);
+ return name;
}
static void funcinfo (lua_Debug *ar, Closure *cl) {
- if (noLuaClosure(cl)) {
- ar->source = "=[C]";
- ar->linedefined = -1;
- ar->lastlinedefined = -1;
- ar->what = "C";
- }
- else {
- Proto *p = cl->l.p;
- ar->source = p->source ? getstr(p->source) : "=?";
- ar->linedefined = p->linedefined;
- ar->lastlinedefined = p->lastlinedefined;
- ar->what = (ar->linedefined == 0) ? "main" : "Lua";
- }
- luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
+ if (noLuaClosure(cl)) {
+ ar->source = "=[C]";
+ ar->linedefined = -1;
+ ar->lastlinedefined = -1;
+ ar->what = "C";
+ }
+ else {
+ Proto *p = cl->l.p;
+ ar->source = p->source ? getstr(p->source) : "=?";
+ ar->linedefined = p->linedefined;
+ ar->lastlinedefined = p->lastlinedefined;
+ ar->what = (ar->linedefined == 0) ? "main" : "Lua";
+ }
+ luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
}
static void collectvalidlines (lua_State *L, Closure *f) {
- if (noLuaClosure(f)) {
- setnilvalue(L->top);
- api_incr_top(L);
- }
- else {
- int i;
- TValue v;
- int *lineinfo = f->l.p->lineinfo;
- Table *t = luaH_new(L); /* new table to store active lines */
- sethvalue(L, L->top, t); /* push it on stack */
- api_incr_top(L);
- setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
- for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
- luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
- }
+ if (noLuaClosure(f)) {
+ setnilvalue(L->top);
+ api_incr_top(L);
+ }
+ else {
+ int i;
+ TValue v;
+ int *lineinfo = f->l.p->lineinfo;
+ Table *t = luaH_new(L); /* new table to store active lines */
+ sethvalue(L, L->top, t); /* push it on stack */
+ api_incr_top(L);
+ setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
+ for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
+ luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
+ }
}
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
- Closure *f, CallInfo *ci) {
- int status = 1;
- for (; *what; what++) {
- switch (*what) {
- case 'S': {
- funcinfo(ar, f);
- break;
- }
- case 'l': {
- ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
- break;
- }
- case 'u': {
- ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
- if (noLuaClosure(f)) {
- ar->isvararg = 1;
- ar->nparams = 0;
- }
- else {
- ar->isvararg = f->l.p->is_vararg;
- ar->nparams = f->l.p->numparams;
- }
- break;
- }
- case 't': {
- ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;
- break;
- }
- case 'n': {
- /* calling function is a known Lua function? */
- if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
- ar->namewhat = getfuncname(L, ci->previous, &ar->name);
- else
- ar->namewhat = NULL;
- if (ar->namewhat == NULL) {
- ar->namewhat = ""; /* not found */
- ar->name = NULL;
- }
- break;
- }
- case 'L':
- case 'f': /* handled by lua_getinfo */
- break;
- default: status = 0; /* invalid option */
- }
- }
- return status;
+ Closure *f, CallInfo *ci) {
+ int status = 1;
+ for (; *what; what++) {
+ switch (*what) {
+ case 'S': {
+ funcinfo(ar, f);
+ break;
+ }
+ case 'l': {
+ ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;
+ break;
+ }
+ case 'u': {
+ ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
+ if (noLuaClosure(f)) {
+ ar->isvararg = 1;
+ ar->nparams = 0;
+ }
+ else {
+ ar->isvararg = f->l.p->is_vararg;
+ ar->nparams = f->l.p->numparams;
+ }
+ break;
+ }
+ case 't': {
+ ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;
+ break;
+ }
+ case 'n': {
+ /* calling function is a known Lua function? */
+ if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
+ ar->namewhat = getfuncname(L, ci->previous, &ar->name);
+ else
+ ar->namewhat = NULL;
+ if (ar->namewhat == NULL) {
+ ar->namewhat = ""; /* not found */
+ ar->name = NULL;
+ }
+ break;
+ }
+ case 'L':
+ case 'f': /* handled by lua_getinfo */
+ break;
+ default: status = 0; /* invalid option */
+ }
+ }
+ return status;
}
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
- int status;
- Closure *cl;
- CallInfo *ci;
- StkId func;
- lua_lock(L);
- if (*what == '>') {
- ci = NULL;
- func = L->top - 1;
- api_check(L, ttisfunction(func), "function expected");
- what++; /* skip the '>' */
- L->top--; /* pop function */
- }
- else {
- ci = ar->i_ci;
- func = ci->func;
- lua_assert(ttisfunction(ci->func));
- }
- cl = ttisclosure(func) ? clvalue(func) : NULL;
- status = auxgetinfo(L, what, ar, cl, ci);
- if (strchr(what, 'f')) {
- setobjs2s(L, L->top, func);
- api_incr_top(L);
- }
- if (strchr(what, 'L'))
- collectvalidlines(L, cl);
- lua_unlock(L);
- return status;
+ int status;
+ Closure *cl;
+ CallInfo *ci;
+ StkId func;
+ lua_lock(L);
+ if (*what == '>') {
+ ci = NULL;
+ func = L->top - 1;
+ api_check(L, ttisfunction(func), "function expected");
+ what++; /* skip the '>' */
+ L->top--; /* pop function */
+ }
+ else {
+ ci = ar->i_ci;
+ func = ci->func;
+ lua_assert(ttisfunction(ci->func));
+ }
+ cl = ttisclosure(func) ? clvalue(func) : NULL;
+ status = auxgetinfo(L, what, ar, cl, ci);
+ if (strchr(what, 'f')) {
+ setobjs2s(L, L->top, func);
+ api_incr_top(L);
+ }
+ if (strchr(what, 'L'))
+ collectvalidlines(L, cl);
+ lua_unlock(L);
+ return status;
}
@@ -301,29 +301,29 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
*/
static const char *getobjname (Proto *p, int lastpc, int reg,
- const char **name);
+ const char **name);
/*
** find a "name" for the RK value 'c'
*/
static void kname (Proto *p, int pc, int c, const char **name) {
- if (ISK(c)) { /* is 'c' a constant? */
- TValue *kvalue = &p->k[INDEXK(c)];
- if (ttisstring(kvalue)) { /* literal constant? */
- *name = svalue(kvalue); /* it is its own name */
- return;
- }
- /* else no reasonable name found */
- }
- else { /* 'c' is a register */
- const char *what = getobjname(p, pc, c, name); /* search for 'c' */
- if (what && *what == 'c') { /* found a constant name? */
- return; /* 'name' already filled */
- }
- /* else no reasonable name found */
- }
- *name = "?"; /* no reasonable name found */
+ if (ISK(c)) { /* is 'c' a constant? */
+ TValue *kvalue = &p->k[INDEXK(c)];
+ if (ttisstring(kvalue)) { /* literal constant? */
+ *name = svalue(kvalue); /* it is its own name */
+ return;
+ }
+ /* else no reasonable name found */
+ }
+ else { /* 'c' is a register */
+ const char *what = getobjname(p, pc, c, name); /* search for 'c' */
+ if (what && *what == 'c') { /* found a constant name? */
+ return; /* 'name' already filled */
+ }
+ /* else no reasonable name found */
+ }
+ *name = "?"; /* no reasonable name found */
}
@@ -331,140 +331,140 @@ static void kname (Proto *p, int pc, int c, const char **name) {
** try to find last instruction before 'lastpc' that modified register 'reg'
*/
static int findsetreg (Proto *p, int lastpc, int reg) {
- int pc;
- int setreg = -1; /* keep last instruction that changed 'reg' */
- for (pc = 0; pc < lastpc; pc++) {
- Instruction i = p->code[pc];
- OpCode op = GET_OPCODE(i);
- int a = GETARG_A(i);
- switch (op) {
- case OP_LOADNIL: {
- int b = GETARG_B(i);
- if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
- setreg = pc;
- break;
- }
- case OP_TFORCALL: {
- if (reg >= a + 2) setreg = pc; /* affect all regs above its base */
- break;
- }
- case OP_CALL:
- case OP_TAILCALL: {
- if (reg >= a) setreg = pc; /* affect all registers above base */
- break;
- }
- case OP_JMP: {
- int b = GETARG_sBx(i);
- int dest = pc + 1 + b;
- /* jump is forward and do not skip `lastpc'? */
- if (pc < dest && dest <= lastpc)
- pc += b; /* do the jump */
- break;
- }
- case OP_TEST: {
- if (reg == a) setreg = pc; /* jumped code can change 'a' */
- break;
- }
- default:
- if (testAMode(op) && reg == a) /* any instruction that set A */
- setreg = pc;
- break;
- }
- }
- return setreg;
+ int pc;
+ int setreg = -1; /* keep last instruction that changed 'reg' */
+ for (pc = 0; pc < lastpc; pc++) {
+ Instruction i = p->code[pc];
+ OpCode op = GET_OPCODE(i);
+ int a = GETARG_A(i);
+ switch (op) {
+ case OP_LOADNIL: {
+ int b = GETARG_B(i);
+ if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
+ setreg = pc;
+ break;
+ }
+ case OP_TFORCALL: {
+ if (reg >= a + 2) setreg = pc; /* affect all regs above its base */
+ break;
+ }
+ case OP_CALL:
+ case OP_TAILCALL: {
+ if (reg >= a) setreg = pc; /* affect all registers above base */
+ break;
+ }
+ case OP_JMP: {
+ int b = GETARG_sBx(i);
+ int dest = pc + 1 + b;
+ /* jump is forward and do not skip `lastpc'? */
+ if (pc < dest && dest <= lastpc)
+ pc += b; /* do the jump */
+ break;
+ }
+ case OP_TEST: {
+ if (reg == a) setreg = pc; /* jumped code can change 'a' */
+ break;
+ }
+ default:
+ if (testAMode(op) && reg == a) /* any instruction that set A */
+ setreg = pc;
+ break;
+ }
+ }
+ return setreg;
}
static const char *getobjname (Proto *p, int lastpc, int reg,
- const char **name) {
- int pc;
- *name = luaF_getlocalname(p, reg + 1, lastpc);
- if (*name) /* is a local? */
- return "local";
- /* else try symbolic execution */
- pc = findsetreg(p, lastpc, reg);
- if (pc != -1) { /* could find instruction? */
- Instruction i = p->code[pc];
- OpCode op = GET_OPCODE(i);
- switch (op) {
- case OP_MOVE: {
- int b = GETARG_B(i); /* move from 'b' to 'a' */
- if (b < GETARG_A(i))
- return getobjname(p, pc, b, name); /* get name for 'b' */
- break;
- }
- case OP_GETTABUP:
- case OP_GETTABLE: {
- int k = GETARG_C(i); /* key index */
- int t = GETARG_B(i); /* table index */
- const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
- ? luaF_getlocalname(p, t + 1, pc)
- : upvalname(p, t);
- kname(p, pc, k, name);
- return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
- }
- case OP_GETUPVAL: {
- *name = upvalname(p, GETARG_B(i));
- return "upvalue";
- }
- case OP_LOADK:
- case OP_LOADKX: {
- int b = (op == OP_LOADK) ? GETARG_Bx(i)
- : GETARG_Ax(p->code[pc + 1]);
- if (ttisstring(&p->k[b])) {
- *name = svalue(&p->k[b]);
- return "constant";
- }
- break;
- }
- case OP_SELF: {
- int k = GETARG_C(i); /* key index */
- kname(p, pc, k, name);
- return "method";
- }
- default: break; /* go through to return NULL */
- }
- }
- return NULL; /* could not find reasonable name */
+ const char **name) {
+ int pc;
+ *name = luaF_getlocalname(p, reg + 1, lastpc);
+ if (*name) /* is a local? */
+ return "local";
+ /* else try symbolic execution */
+ pc = findsetreg(p, lastpc, reg);
+ if (pc != -1) { /* could find instruction? */
+ Instruction i = p->code[pc];
+ OpCode op = GET_OPCODE(i);
+ switch (op) {
+ case OP_MOVE: {
+ int b = GETARG_B(i); /* move from 'b' to 'a' */
+ if (b < GETARG_A(i))
+ return getobjname(p, pc, b, name); /* get name for 'b' */
+ break;
+ }
+ case OP_GETTABUP:
+ case OP_GETTABLE: {
+ int k = GETARG_C(i); /* key index */
+ int t = GETARG_B(i); /* table index */
+ const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
+ ? luaF_getlocalname(p, t + 1, pc)
+ : upvalname(p, t);
+ kname(p, pc, k, name);
+ return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
+ }
+ case OP_GETUPVAL: {
+ *name = upvalname(p, GETARG_B(i));
+ return "upvalue";
+ }
+ case OP_LOADK:
+ case OP_LOADKX: {
+ int b = (op == OP_LOADK) ? GETARG_Bx(i)
+ : GETARG_Ax(p->code[pc + 1]);
+ if (ttisstring(&p->k[b])) {
+ *name = svalue(&p->k[b]);
+ return "constant";
+ }
+ break;
+ }
+ case OP_SELF: {
+ int k = GETARG_C(i); /* key index */
+ kname(p, pc, k, name);
+ return "method";
+ }
+ default: break; /* go through to return NULL */
+ }
+ }
+ return NULL; /* could not find reasonable name */
}
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
- TMS tm;
- Proto *p = ci_func(ci)->p; /* calling function */
- int pc = currentpc(ci); /* calling instruction index */
- Instruction i = p->code[pc]; /* calling instruction */
- switch (GET_OPCODE(i)) {
- case OP_CALL:
- case OP_TAILCALL: /* get function name */
- return getobjname(p, pc, GETARG_A(i), name);
- case OP_TFORCALL: { /* for iterator */
- *name = "for iterator";
- return "for iterator";
- }
- /* all other instructions can call only through metamethods */
- case OP_SELF:
- case OP_GETTABUP:
- case OP_GETTABLE: tm = TM_INDEX; break;
- case OP_SETTABUP:
- case OP_SETTABLE: tm = TM_NEWINDEX; break;
- case OP_EQ: tm = TM_EQ; break;
- case OP_ADD: tm = TM_ADD; break;
- case OP_SUB: tm = TM_SUB; break;
- case OP_MUL: tm = TM_MUL; break;
- case OP_DIV: tm = TM_DIV; break;
- case OP_MOD: tm = TM_MOD; break;
- case OP_POW: tm = TM_POW; break;
- case OP_UNM: tm = TM_UNM; break;
- case OP_LEN: tm = TM_LEN; break;
- case OP_LT: tm = TM_LT; break;
- case OP_LE: tm = TM_LE; break;
- case OP_CONCAT: tm = TM_CONCAT; break;
- default:
- return NULL; /* else no useful name can be found */
- }
- *name = getstr(G(L)->tmname[tm]);
- return "metamethod";
+ TMS tm;
+ Proto *p = ci_func(ci)->p; /* calling function */
+ int pc = currentpc(ci); /* calling instruction index */
+ Instruction i = p->code[pc]; /* calling instruction */
+ switch (GET_OPCODE(i)) {
+ case OP_CALL:
+ case OP_TAILCALL: /* get function name */
+ return getobjname(p, pc, GETARG_A(i), name);
+ case OP_TFORCALL: { /* for iterator */
+ *name = "for iterator";
+ return "for iterator";
+ }
+ /* all other instructions can call only through metamethods */
+ case OP_SELF:
+ case OP_GETTABUP:
+ case OP_GETTABLE: tm = TM_INDEX; break;
+ case OP_SETTABUP:
+ case OP_SETTABLE: tm = TM_NEWINDEX; break;
+ case OP_EQ: tm = TM_EQ; break;
+ case OP_ADD: tm = TM_ADD; break;
+ case OP_SUB: tm = TM_SUB; break;
+ case OP_MUL: tm = TM_MUL; break;
+ case OP_DIV: tm = TM_DIV; break;
+ case OP_MOD: tm = TM_MOD; break;
+ case OP_POW: tm = TM_POW; break;
+ case OP_UNM: tm = TM_UNM; break;
+ case OP_LEN: tm = TM_LEN; break;
+ case OP_LT: tm = TM_LT; break;
+ case OP_LE: tm = TM_LE; break;
+ case OP_CONCAT: tm = TM_CONCAT; break;
+ default:
+ return NULL; /* else no useful name can be found */
+ }
+ *name = getstr(G(L)->tmname[tm]);
+ return "metamethod";
}
/* }====================================================== */
@@ -476,105 +476,104 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
** (used only for error messages, so efficiency is not a big concern)
*/
static int isinstack (CallInfo *ci, const TValue *o) {
- StkId p;
- for (p = ci->u.l.base; p < ci->top; p++)
- if (o == p) return 1;
- return 0;
+ StkId p;
+ for (p = ci->u.l.base; p < ci->top; p++)
+ if (o == p) return 1;
+ return 0;
}
static const char *getupvalname (CallInfo *ci, const TValue *o,
- const char **name) {
- LClosure *c = ci_func(ci);
- int i;
- for (i = 0; i < c->nupvalues; i++) {
- if (c->upvals[i]->v == o) {
- *name = upvalname(c->p, i);
- return "upvalue";
- }
- }
- return NULL;
+ const char **name) {
+ LClosure *c = ci_func(ci);
+ int i;
+ for (i = 0; i < c->nupvalues; i++) {
+ if (c->upvals[i]->v == o) {
+ *name = upvalname(c->p, i);
+ return "upvalue";
+ }
+ }
+ return NULL;
}
l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
- CallInfo *ci = L->ci;
- const char *name = NULL;
- const char *t = objtypename(o);
- const char *kind = NULL;
- if (isLua(ci)) {
- kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
- if (!kind && isinstack(ci, o)) /* no? try a register */
- kind = getobjname(ci_func(ci)->p, currentpc(ci),
- cast_int(o - ci->u.l.base), &name);
- }
- if (kind)
- luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
- op, kind, name, t);
- else
- luaG_runerror(L, "attempt to %s a %s value", op, t);
+ CallInfo *ci = L->ci;
+ const char *name = NULL;
+ const char *t = objtypename(o);
+ const char *kind = NULL;
+ if (isLua(ci)) {
+ kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */
+ if (!kind && isinstack(ci, o)) /* no? try a register */
+ kind = getobjname(ci_func(ci)->p, currentpc(ci),
+ cast_int(o - ci->u.l.base), &name);
+ }
+ if (kind)
+ luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)",
+ op, kind, name, t);
+ else
+ luaG_runerror(L, "attempt to %s a %s value", op, t);
}
l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
- if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
- lua_assert(!ttisstring(p1) && !ttisnumber(p2));
- luaG_typeerror(L, p1, "concatenate");
+ if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
+ lua_assert(!ttisstring(p1) && !ttisnumber(p2));
+ luaG_typeerror(L, p1, "concatenate");
}
l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
- TValue temp;
- if (luaV_tonumber(p1, &temp) == NULL)
- p2 = p1; /* first operand is wrong */
- luaG_typeerror(L, p2, "perform arithmetic on");
+ TValue temp;
+ if (luaV_tonumber(p1, &temp) == NULL)
+ p2 = p1; /* first operand is wrong */
+ luaG_typeerror(L, p2, "perform arithmetic on");
}
l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
- const char *t1 = objtypename(p1);
- const char *t2 = objtypename(p2);
- if (t1 == t2)
- luaG_runerror(L, "attempt to compare two %s values", t1);
- else
- luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
+ const char *t1 = objtypename(p1);
+ const char *t2 = objtypename(p2);
+ if (t1 == t2)
+ luaG_runerror(L, "attempt to compare two %s values", t1);
+ else
+ luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
}
static void addinfo (lua_State *L, const char *msg) {
- CallInfo *ci = L->ci;
- if (isLua(ci)) { /* is Lua code? */
- char buff[LUA_IDSIZE]; /* add file:line information */
- int line = currentline(ci);
- TString *src = ci_func(ci)->p->source;
- if (src)
- luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
- else { /* no source available; use "?" instead */
- buff[0] = '?'; buff[1] = '\0';
- }
- luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
- }
+ CallInfo *ci = L->ci;
+ if (isLua(ci)) { /* is Lua code? */
+ char buff[LUA_IDSIZE]; /* add file:line information */
+ int line = currentline(ci);
+ TString *src = ci_func(ci)->p->source;
+ if (src)
+ luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
+ else { /* no source available; use "?" instead */
+ buff[0] = '?'; buff[1] = '\0';
+ }
+ luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
+ }
}
l_noret luaG_errormsg (lua_State *L) {
- if (L->errfunc != 0) { /* is there an error handling function? */
- StkId errfunc = restorestack(L, L->errfunc);
- if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
- setobjs2s(L, L->top, L->top - 1); /* move argument */
- setobjs2s(L, L->top - 1, errfunc); /* push function */
- L->top++;
- luaD_call(L, L->top - 2, 1, 0); /* call it */
- }
- luaD_throw(L, LUA_ERRRUN);
+ if (L->errfunc != 0) { /* is there an error handling function? */
+ StkId errfunc = restorestack(L, L->errfunc);
+ if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
+ setobjs2s(L, L->top, L->top - 1); /* move argument */
+ setobjs2s(L, L->top - 1, errfunc); /* push function */
+ L->top++;
+ luaD_call(L, L->top - 2, 1, 0); /* call it */
+ }
+ luaD_throw(L, LUA_ERRRUN);
}
l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
- va_list argp;
- va_start(argp, fmt);
- addinfo(L, luaO_pushvfstring(L, fmt, argp));
- va_end(argp);
- luaG_errormsg(L);
+ va_list argp;
+ va_start(argp, fmt);
+ addinfo(L, luaO_pushvfstring(L, fmt, argp));
+ va_end(argp);
+ luaG_errormsg(L);
}
-
diff --git a/src/lib/lua/ldebug.h b/src/lib/lua/ldebug.h
index fe39556b062..8776006e7f5 100644
--- a/src/lib/lua/ldebug.h
+++ b/src/lib/lua/ldebug.h
@@ -11,23 +11,23 @@
#include "lstate.h"
-#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
+#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
-#define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
+#define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
-#define resethookcount(L) (L->hookcount = L->basehookcount)
+#define resethookcount(L) (L->hookcount = L->basehookcount)
/* Active Lua function (given call info) */
-#define ci_func(ci) (clLvalue((ci)->func))
+#define ci_func(ci) (clLvalue((ci)->func))
LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,
- const char *opname);
+ const char *opname);
LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2);
LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1,
- const TValue *p2);
+ const TValue *p2);
LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
- const TValue *p2);
+ const TValue *p2);
LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
diff --git a/src/lib/lua/ldo.c b/src/lib/lua/ldo.c
index aafa3dca234..154dd4e739c 100644
--- a/src/lib/lua/ldo.c
+++ b/src/lib/lua/ldo.c
@@ -50,22 +50,22 @@
#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
/* C++ exceptions */
-#define LUAI_THROW(L,c) throw(c)
+#define LUAI_THROW(L,c) throw(c)
#define LUAI_TRY(L,c,a) \
try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
-#define luai_jmpbuf int /* dummy variable */
+#define luai_jmpbuf int /* dummy variable */
#elif defined(LUA_USE_ULONGJMP)
/* in Unix, try _longjmp/_setjmp (more efficient) */
-#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
-#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
-#define luai_jmpbuf jmp_buf
+#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
+#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
+#define luai_jmpbuf jmp_buf
#else
/* default handling with long jumps */
-#define LUAI_THROW(L,c) longjmp((c)->b, 1)
-#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
-#define luai_jmpbuf jmp_buf
+#define LUAI_THROW(L,c) longjmp((c)->b, 1)
+#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
+#define luai_jmpbuf jmp_buf
#endif
@@ -75,213 +75,213 @@
/* chain list of long jump buffers */
struct lua_longjmp {
- struct lua_longjmp *previous;
- luai_jmpbuf b;
- volatile int status; /* error code */
+ struct lua_longjmp *previous;
+ luai_jmpbuf b;
+ volatile int status; /* error code */
};
static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
- switch (errcode) {
- case LUA_ERRMEM: { /* memory error? */
- setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
- break;
- }
- case LUA_ERRERR: {
- setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
- break;
- }
- default: {
- setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
- break;
- }
- }
- L->top = oldtop + 1;
+ switch (errcode) {
+ case LUA_ERRMEM: { /* memory error? */
+ setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
+ break;
+ }
+ case LUA_ERRERR: {
+ setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
+ break;
+ }
+ default: {
+ setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
+ break;
+ }
+ }
+ L->top = oldtop + 1;
}
l_noret luaD_throw (lua_State *L, int errcode) {
- if (L->errorJmp) { /* thread has an error handler? */
- L->errorJmp->status = errcode; /* set status */
- LUAI_THROW(L, L->errorJmp); /* jump to it */
- }
- else { /* thread has no error handler */
- L->status = cast_byte(errcode); /* mark it as dead */
- if (G(L)->mainthread->errorJmp) { /* main thread has a handler? */
- setobjs2s(L, G(L)->mainthread->top++, L->top - 1); /* copy error obj. */
- luaD_throw(G(L)->mainthread, errcode); /* re-throw in main thread */
- }
- else { /* no handler at all; abort */
- if (G(L)->panic) { /* panic function? */
- lua_unlock(L);
- G(L)->panic(L); /* call it (last chance to jump out) */
- }
- abort();
- }
- }
+ if (L->errorJmp) { /* thread has an error handler? */
+ L->errorJmp->status = errcode; /* set status */
+ LUAI_THROW(L, L->errorJmp); /* jump to it */
+ }
+ else { /* thread has no error handler */
+ L->status = cast_byte(errcode); /* mark it as dead */
+ if (G(L)->mainthread->errorJmp) { /* main thread has a handler? */
+ setobjs2s(L, G(L)->mainthread->top++, L->top - 1); /* copy error obj. */
+ luaD_throw(G(L)->mainthread, errcode); /* re-throw in main thread */
+ }
+ else { /* no handler at all; abort */
+ if (G(L)->panic) { /* panic function? */
+ lua_unlock(L);
+ G(L)->panic(L); /* call it (last chance to jump out) */
+ }
+ abort();
+ }
+ }
}
int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
- unsigned short oldnCcalls = L->nCcalls;
- struct lua_longjmp lj;
- lj.status = LUA_OK;
- lj.previous = L->errorJmp; /* chain new error handler */
- L->errorJmp = &lj;
- LUAI_TRY(L, &lj,
- (*f)(L, ud);
- );
- L->errorJmp = lj.previous; /* restore old error handler */
- L->nCcalls = oldnCcalls;
- return lj.status;
+ unsigned short oldnCcalls = L->nCcalls;
+ struct lua_longjmp lj;
+ lj.status = LUA_OK;
+ lj.previous = L->errorJmp; /* chain new error handler */
+ L->errorJmp = &lj;
+ LUAI_TRY(L, &lj,
+ (*f)(L, ud);
+ );
+ L->errorJmp = lj.previous; /* restore old error handler */
+ L->nCcalls = oldnCcalls;
+ return lj.status;
}
/* }====================================================== */
static void correctstack (lua_State *L, TValue *oldstack) {
- CallInfo *ci;
- GCObject *up;
- L->top = (L->top - oldstack) + L->stack;
- for (up = L->openupval; up != NULL; up = up->gch.next)
- gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;
- for (ci = L->ci; ci != NULL; ci = ci->previous) {
- ci->top = (ci->top - oldstack) + L->stack;
- ci->func = (ci->func - oldstack) + L->stack;
- if (isLua(ci))
- ci->u.l.base = (ci->u.l.base - oldstack) + L->stack;
- }
+ CallInfo *ci;
+ GCObject *up;
+ L->top = (L->top - oldstack) + L->stack;
+ for (up = L->openupval; up != NULL; up = up->gch.next)
+ gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;
+ for (ci = L->ci; ci != NULL; ci = ci->previous) {
+ ci->top = (ci->top - oldstack) + L->stack;
+ ci->func = (ci->func - oldstack) + L->stack;
+ if (isLua(ci))
+ ci->u.l.base = (ci->u.l.base - oldstack) + L->stack;
+ }
}
/* some space for error handling */
-#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
+#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
void luaD_reallocstack (lua_State *L, int newsize) {
- TValue *oldstack = L->stack;
- int lim = L->stacksize;
- lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
- lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);
- luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);
- for (; lim < newsize; lim++)
- setnilvalue(L->stack + lim); /* erase new segment */
- L->stacksize = newsize;
- L->stack_last = L->stack + newsize - EXTRA_STACK;
- correctstack(L, oldstack);
+ TValue *oldstack = L->stack;
+ int lim = L->stacksize;
+ lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
+ lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);
+ luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);
+ for (; lim < newsize; lim++)
+ setnilvalue(L->stack + lim); /* erase new segment */
+ L->stacksize = newsize;
+ L->stack_last = L->stack + newsize - EXTRA_STACK;
+ correctstack(L, oldstack);
}
void luaD_growstack (lua_State *L, int n) {
- int size = L->stacksize;
- if (size > LUAI_MAXSTACK) /* error after extra size? */
- luaD_throw(L, LUA_ERRERR);
- else {
- int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;
- int newsize = 2 * size;
- if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;
- if (newsize < needed) newsize = needed;
- if (newsize > LUAI_MAXSTACK) { /* stack overflow? */
- luaD_reallocstack(L, ERRORSTACKSIZE);
- luaG_runerror(L, "stack overflow");
- }
- else
- luaD_reallocstack(L, newsize);
- }
+ int size = L->stacksize;
+ if (size > LUAI_MAXSTACK) /* error after extra size? */
+ luaD_throw(L, LUA_ERRERR);
+ else {
+ int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;
+ int newsize = 2 * size;
+ if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;
+ if (newsize < needed) newsize = needed;
+ if (newsize > LUAI_MAXSTACK) { /* stack overflow? */
+ luaD_reallocstack(L, ERRORSTACKSIZE);
+ luaG_runerror(L, "stack overflow");
+ }
+ else
+ luaD_reallocstack(L, newsize);
+ }
}
static int stackinuse (lua_State *L) {
- CallInfo *ci;
- StkId lim = L->top;
- for (ci = L->ci; ci != NULL; ci = ci->previous) {
- lua_assert(ci->top <= L->stack_last);
- if (lim < ci->top) lim = ci->top;
- }
- return cast_int(lim - L->stack) + 1; /* part of stack in use */
+ CallInfo *ci;
+ StkId lim = L->top;
+ for (ci = L->ci; ci != NULL; ci = ci->previous) {
+ lua_assert(ci->top <= L->stack_last);
+ if (lim < ci->top) lim = ci->top;
+ }
+ return cast_int(lim - L->stack) + 1; /* part of stack in use */
}
void luaD_shrinkstack (lua_State *L) {
- int inuse = stackinuse(L);
- int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;
- if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK;
- if (inuse > LUAI_MAXSTACK || /* handling stack overflow? */
- goodsize >= L->stacksize) /* would grow instead of shrink? */
- condmovestack(L); /* don't change stack (change only for debugging) */
- else
- luaD_reallocstack(L, goodsize); /* shrink it */
+ int inuse = stackinuse(L);
+ int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;
+ if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK;
+ if (inuse > LUAI_MAXSTACK || /* handling stack overflow? */
+ goodsize >= L->stacksize) /* would grow instead of shrink? */
+ condmovestack(L); /* don't change stack (change only for debugging) */
+ else
+ luaD_reallocstack(L, goodsize); /* shrink it */
}
void luaD_hook (lua_State *L, int event, int line) {
- lua_Hook hook = L->hook;
- if (hook && L->allowhook) {
- CallInfo *ci = L->ci;
- ptrdiff_t top = savestack(L, L->top);
- ptrdiff_t ci_top = savestack(L, ci->top);
- lua_Debug ar;
- ar.event = event;
- ar.currentline = line;
- ar.i_ci = ci;
- luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
- ci->top = L->top + LUA_MINSTACK;
- lua_assert(ci->top <= L->stack_last);
- L->allowhook = 0; /* cannot call hooks inside a hook */
- ci->callstatus |= CIST_HOOKED;
- lua_unlock(L);
- (*hook)(L, &ar);
- lua_lock(L);
- lua_assert(!L->allowhook);
- L->allowhook = 1;
- ci->top = restorestack(L, ci_top);
- L->top = restorestack(L, top);
- ci->callstatus &= ~CIST_HOOKED;
- }
+ lua_Hook hook = L->hook;
+ if (hook && L->allowhook) {
+ CallInfo *ci = L->ci;
+ ptrdiff_t top = savestack(L, L->top);
+ ptrdiff_t ci_top = savestack(L, ci->top);
+ lua_Debug ar;
+ ar.event = event;
+ ar.currentline = line;
+ ar.i_ci = ci;
+ luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
+ ci->top = L->top + LUA_MINSTACK;
+ lua_assert(ci->top <= L->stack_last);
+ L->allowhook = 0; /* cannot call hooks inside a hook */
+ ci->callstatus |= CIST_HOOKED;
+ lua_unlock(L);
+ (*hook)(L, &ar);
+ lua_lock(L);
+ lua_assert(!L->allowhook);
+ L->allowhook = 1;
+ ci->top = restorestack(L, ci_top);
+ L->top = restorestack(L, top);
+ ci->callstatus &= ~CIST_HOOKED;
+ }
}
static void callhook (lua_State *L, CallInfo *ci) {
- int hook = LUA_HOOKCALL;
- ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */
- if (isLua(ci->previous) &&
- GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {
- ci->callstatus |= CIST_TAIL;
- hook = LUA_HOOKTAILCALL;
- }
- luaD_hook(L, hook, -1);
- ci->u.l.savedpc--; /* correct 'pc' */
+ int hook = LUA_HOOKCALL;
+ ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */
+ if (isLua(ci->previous) &&
+ GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {
+ ci->callstatus |= CIST_TAIL;
+ hook = LUA_HOOKTAILCALL;
+ }
+ luaD_hook(L, hook, -1);
+ ci->u.l.savedpc--; /* correct 'pc' */
}
static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
- int i;
- int nfixargs = p->numparams;
- StkId base, fixed;
- lua_assert(actual >= nfixargs);
- /* move fixed parameters to final position */
- fixed = L->top - actual; /* first fixed argument */
- base = L->top; /* final position of first argument */
- for (i=0; i<nfixargs; i++) {
- setobjs2s(L, L->top++, fixed + i);
- setnilvalue(fixed + i);
- }
- return base;
+ int i;
+ int nfixargs = p->numparams;
+ StkId base, fixed;
+ lua_assert(actual >= nfixargs);
+ /* move fixed parameters to final position */
+ fixed = L->top - actual; /* first fixed argument */
+ base = L->top; /* final position of first argument */
+ for (i=0; i<nfixargs; i++) {
+ setobjs2s(L, L->top++, fixed + i);
+ setnilvalue(fixed + i);
+ }
+ return base;
}
static StkId tryfuncTM (lua_State *L, StkId func) {
- const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
- StkId p;
- ptrdiff_t funcr = savestack(L, func);
- if (!ttisfunction(tm))
- luaG_typeerror(L, func, "call");
- /* Open a hole inside the stack at `func' */
- for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
- incr_top(L);
- func = restorestack(L, funcr); /* previous call may change stack */
- setobj2s(L, func, tm); /* tag method is the new function to be called */
- return func;
+ const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
+ StkId p;
+ ptrdiff_t funcr = savestack(L, func);
+ if (!ttisfunction(tm))
+ luaG_typeerror(L, func, "call");
+ /* Open a hole inside the stack at `func' */
+ for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
+ incr_top(L);
+ func = restorestack(L, funcr); /* previous call may change stack */
+ setobj2s(L, func, tm); /* tag method is the new function to be called */
+ return func;
}
@@ -293,87 +293,87 @@ static StkId tryfuncTM (lua_State *L, StkId func) {
** returns true if function has been executed (C function)
*/
int luaD_precall (lua_State *L, StkId func, int nresults) {
- lua_CFunction f;
- CallInfo *ci;
- int n; /* number of arguments (Lua) or returns (C) */
- ptrdiff_t funcr = savestack(L, func);
- switch (ttype(func)) {
- case LUA_TLCF: /* light C function */
- f = fvalue(func);
- goto Cfunc;
- case LUA_TCCL: { /* C closure */
- f = clCvalue(func)->f;
- Cfunc:
- luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
- ci = next_ci(L); /* now 'enter' new function */
- ci->nresults = nresults;
- ci->func = restorestack(L, funcr);
- ci->top = L->top + LUA_MINSTACK;
- lua_assert(ci->top <= L->stack_last);
- ci->callstatus = 0;
- luaC_checkGC(L); /* stack grow uses memory */
- if (L->hookmask & LUA_MASKCALL)
- luaD_hook(L, LUA_HOOKCALL, -1);
- lua_unlock(L);
- n = (*f)(L); /* do the actual call */
- lua_lock(L);
- api_checknelems(L, n);
- luaD_poscall(L, L->top - n);
- return 1;
- }
- case LUA_TLCL: { /* Lua function: prepare its call */
- StkId base;
- Proto *p = clLvalue(func)->p;
- luaD_checkstack(L, p->maxstacksize);
- func = restorestack(L, funcr);
- n = cast_int(L->top - func) - 1; /* number of real arguments */
- for (; n < p->numparams; n++)
- setnilvalue(L->top++); /* complete missing arguments */
- base = (!p->is_vararg) ? func + 1 : adjust_varargs(L, p, n);
- ci = next_ci(L); /* now 'enter' new function */
- ci->nresults = nresults;
- ci->func = func;
- ci->u.l.base = base;
- ci->top = base + p->maxstacksize;
- lua_assert(ci->top <= L->stack_last);
- ci->u.l.savedpc = p->code; /* starting point */
- ci->callstatus = CIST_LUA;
- L->top = ci->top;
- luaC_checkGC(L); /* stack grow uses memory */
- if (L->hookmask & LUA_MASKCALL)
- callhook(L, ci);
- return 0;
- }
- default: { /* not a function */
- func = tryfuncTM(L, func); /* retry with 'function' tag method */
- return luaD_precall(L, func, nresults); /* now it must be a function */
- }
- }
+ lua_CFunction f;
+ CallInfo *ci;
+ int n; /* number of arguments (Lua) or returns (C) */
+ ptrdiff_t funcr = savestack(L, func);
+ switch (ttype(func)) {
+ case LUA_TLCF: /* light C function */
+ f = fvalue(func);
+ goto Cfunc;
+ case LUA_TCCL: { /* C closure */
+ f = clCvalue(func)->f;
+ Cfunc:
+ luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
+ ci = next_ci(L); /* now 'enter' new function */
+ ci->nresults = nresults;
+ ci->func = restorestack(L, funcr);
+ ci->top = L->top + LUA_MINSTACK;
+ lua_assert(ci->top <= L->stack_last);
+ ci->callstatus = 0;
+ luaC_checkGC(L); /* stack grow uses memory */
+ if (L->hookmask & LUA_MASKCALL)
+ luaD_hook(L, LUA_HOOKCALL, -1);
+ lua_unlock(L);
+ n = (*f)(L); /* do the actual call */
+ lua_lock(L);
+ api_checknelems(L, n);
+ luaD_poscall(L, L->top - n);
+ return 1;
+ }
+ case LUA_TLCL: { /* Lua function: prepare its call */
+ StkId base;
+ Proto *p = clLvalue(func)->p;
+ luaD_checkstack(L, p->maxstacksize);
+ func = restorestack(L, funcr);
+ n = cast_int(L->top - func) - 1; /* number of real arguments */
+ for (; n < p->numparams; n++)
+ setnilvalue(L->top++); /* complete missing arguments */
+ base = (!p->is_vararg) ? func + 1 : adjust_varargs(L, p, n);
+ ci = next_ci(L); /* now 'enter' new function */
+ ci->nresults = nresults;
+ ci->func = func;
+ ci->u.l.base = base;
+ ci->top = base + p->maxstacksize;
+ lua_assert(ci->top <= L->stack_last);
+ ci->u.l.savedpc = p->code; /* starting point */
+ ci->callstatus = CIST_LUA;
+ L->top = ci->top;
+ luaC_checkGC(L); /* stack grow uses memory */
+ if (L->hookmask & LUA_MASKCALL)
+ callhook(L, ci);
+ return 0;
+ }
+ default: { /* not a function */
+ func = tryfuncTM(L, func); /* retry with 'function' tag method */
+ return luaD_precall(L, func, nresults); /* now it must be a function */
+ }
+ }
}
int luaD_poscall (lua_State *L, StkId firstResult) {
- StkId res;
- int wanted, i;
- CallInfo *ci = L->ci;
- if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {
- if (L->hookmask & LUA_MASKRET) {
- ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */
- luaD_hook(L, LUA_HOOKRET, -1);
- firstResult = restorestack(L, fr);
- }
- L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */
- }
- res = ci->func; /* res == final position of 1st result */
- wanted = ci->nresults;
- L->ci = ci = ci->previous; /* back to caller */
- /* move results to correct place */
- for (i = wanted; i != 0 && firstResult < L->top; i--)
- setobjs2s(L, res++, firstResult++);
- while (i-- > 0)
- setnilvalue(res++);
- L->top = res;
- return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */
+ StkId res;
+ int wanted, i;
+ CallInfo *ci = L->ci;
+ if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {
+ if (L->hookmask & LUA_MASKRET) {
+ ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */
+ luaD_hook(L, LUA_HOOKRET, -1);
+ firstResult = restorestack(L, fr);
+ }
+ L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */
+ }
+ res = ci->func; /* res == final position of 1st result */
+ wanted = ci->nresults;
+ L->ci = ci = ci->previous; /* back to caller */
+ /* move results to correct place */
+ for (i = wanted; i != 0 && firstResult < L->top; i--)
+ setobjs2s(L, res++, firstResult++);
+ while (i-- > 0)
+ setnilvalue(res++);
+ L->top = res;
+ return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */
}
@@ -384,57 +384,57 @@ int luaD_poscall (lua_State *L, StkId firstResult) {
** function position.
*/
void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) {
- if (++L->nCcalls >= LUAI_MAXCCALLS) {
- if (L->nCcalls == LUAI_MAXCCALLS)
- luaG_runerror(L, "C stack overflow");
- else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
- luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
- }
- if (!allowyield) L->nny++;
- if (!luaD_precall(L, func, nResults)) /* is a Lua function? */
- luaV_execute(L); /* call it */
- if (!allowyield) L->nny--;
- L->nCcalls--;
+ if (++L->nCcalls >= LUAI_MAXCCALLS) {
+ if (L->nCcalls == LUAI_MAXCCALLS)
+ luaG_runerror(L, "C stack overflow");
+ else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
+ luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
+ }
+ if (!allowyield) L->nny++;
+ if (!luaD_precall(L, func, nResults)) /* is a Lua function? */
+ luaV_execute(L); /* call it */
+ if (!allowyield) L->nny--;
+ L->nCcalls--;
}
static void finishCcall (lua_State *L) {
- CallInfo *ci = L->ci;
- int n;
- lua_assert(ci->u.c.k != NULL); /* must have a continuation */
- lua_assert(L->nny == 0);
- if (ci->callstatus & CIST_YPCALL) { /* was inside a pcall? */
- ci->callstatus &= ~CIST_YPCALL; /* finish 'lua_pcall' */
- L->errfunc = ci->u.c.old_errfunc;
- }
- /* finish 'lua_callk'/'lua_pcall' */
- adjustresults(L, ci->nresults);
- /* call continuation function */
- if (!(ci->callstatus & CIST_STAT)) /* no call status? */
- ci->u.c.status = LUA_YIELD; /* 'default' status */
- lua_assert(ci->u.c.status != LUA_OK);
- ci->callstatus = (ci->callstatus & ~(CIST_YPCALL | CIST_STAT)) | CIST_YIELDED;
- lua_unlock(L);
- n = (*ci->u.c.k)(L);
- lua_lock(L);
- api_checknelems(L, n);
- /* finish 'luaD_precall' */
- luaD_poscall(L, L->top - n);
+ CallInfo *ci = L->ci;
+ int n;
+ lua_assert(ci->u.c.k != NULL); /* must have a continuation */
+ lua_assert(L->nny == 0);
+ if (ci->callstatus & CIST_YPCALL) { /* was inside a pcall? */
+ ci->callstatus &= ~CIST_YPCALL; /* finish 'lua_pcall' */
+ L->errfunc = ci->u.c.old_errfunc;
+ }
+ /* finish 'lua_callk'/'lua_pcall' */
+ adjustresults(L, ci->nresults);
+ /* call continuation function */
+ if (!(ci->callstatus & CIST_STAT)) /* no call status? */
+ ci->u.c.status = LUA_YIELD; /* 'default' status */
+ lua_assert(ci->u.c.status != LUA_OK);
+ ci->callstatus = (ci->callstatus & ~(CIST_YPCALL | CIST_STAT)) | CIST_YIELDED;
+ lua_unlock(L);
+ n = (*ci->u.c.k)(L);
+ lua_lock(L);
+ api_checknelems(L, n);
+ /* finish 'luaD_precall' */
+ luaD_poscall(L, L->top - n);
}
static void unroll (lua_State *L, void *ud) {
- UNUSED(ud);
- for (;;) {
- if (L->ci == &L->base_ci) /* stack is empty? */
- return; /* coroutine finished normally */
- if (!isLua(L->ci)) /* C function? */
- finishCcall(L);
- else { /* Lua function */
- luaV_finishOp(L); /* finish interrupted instruction */
- luaV_execute(L); /* execute down to higher C 'boundary' */
- }
- }
+ UNUSED(ud);
+ for (;;) {
+ if (L->ci == &L->base_ci) /* stack is empty? */
+ return; /* coroutine finished normally */
+ if (!isLua(L->ci)) /* C function? */
+ finishCcall(L);
+ else { /* Lua function */
+ luaV_finishOp(L); /* finish interrupted instruction */
+ luaV_execute(L); /* execute down to higher C 'boundary' */
+ }
+ }
}
@@ -442,31 +442,31 @@ static void unroll (lua_State *L, void *ud) {
** check whether thread has a suspended protected call
*/
static CallInfo *findpcall (lua_State *L) {
- CallInfo *ci;
- for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */
- if (ci->callstatus & CIST_YPCALL)
- return ci;
- }
- return NULL; /* no pending pcall */
+ CallInfo *ci;
+ for (ci = L->ci; ci != NULL; ci = ci->previous) { /* search for a pcall */
+ if (ci->callstatus & CIST_YPCALL)
+ return ci;
+ }
+ return NULL; /* no pending pcall */
}
static int recover (lua_State *L, int status) {
- StkId oldtop;
- CallInfo *ci = findpcall(L);
- if (ci == NULL) return 0; /* no recovery point */
- /* "finish" luaD_pcall */
- oldtop = restorestack(L, ci->extra);
- luaF_close(L, oldtop);
- seterrorobj(L, status, oldtop);
- L->ci = ci;
- L->allowhook = ci->u.c.old_allowhook;
- L->nny = 0; /* should be zero to be yieldable */
- luaD_shrinkstack(L);
- L->errfunc = ci->u.c.old_errfunc;
- ci->callstatus |= CIST_STAT; /* call has error status */
- ci->u.c.status = status; /* (here it is) */
- return 1; /* continue running the coroutine */
+ StkId oldtop;
+ CallInfo *ci = findpcall(L);
+ if (ci == NULL) return 0; /* no recovery point */
+ /* "finish" luaD_pcall */
+ oldtop = restorestack(L, ci->extra);
+ luaF_close(L, oldtop);
+ seterrorobj(L, status, oldtop);
+ L->ci = ci;
+ L->allowhook = ci->u.c.old_allowhook;
+ L->nny = 0; /* should be zero to be yieldable */
+ luaD_shrinkstack(L);
+ L->errfunc = ci->u.c.old_errfunc;
+ ci->callstatus |= CIST_STAT; /* call has error status */
+ ci->u.c.status = status; /* (here it is) */
+ return 1; /* continue running the coroutine */
}
@@ -476,10 +476,10 @@ static int recover (lua_State *L, int status) {
** error handler and should not kill the coroutine.)
*/
static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {
- L->top = firstArg; /* remove args from the stack */
- setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */
- api_incr_top(L);
- luaD_throw(L, -1); /* jump back to 'lua_resume' */
+ L->top = firstArg; /* remove args from the stack */
+ setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */
+ api_incr_top(L);
+ luaD_throw(L, -1); /* jump back to 'lua_resume' */
}
@@ -487,123 +487,123 @@ static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {
** do the work for 'lua_resume' in protected mode
*/
static void resume (lua_State *L, void *ud) {
- int nCcalls = L->nCcalls;
- StkId firstArg = cast(StkId, ud);
- CallInfo *ci = L->ci;
- if (nCcalls >= LUAI_MAXCCALLS)
- resume_error(L, "C stack overflow", firstArg);
- if (L->status == LUA_OK) { /* may be starting a coroutine */
- if (ci != &L->base_ci) /* not in base level? */
- resume_error(L, "cannot resume non-suspended coroutine", firstArg);
- /* coroutine is in base level; start running it */
- if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */
- luaV_execute(L); /* call it */
- }
- else if (L->status != LUA_YIELD)
- resume_error(L, "cannot resume dead coroutine", firstArg);
- else { /* resuming from previous yield */
- L->status = LUA_OK;
- ci->func = restorestack(L, ci->extra);
- if (isLua(ci)) /* yielded inside a hook? */
- luaV_execute(L); /* just continue running Lua code */
- else { /* 'common' yield */
- if (ci->u.c.k != NULL) { /* does it have a continuation? */
- int n;
- ci->u.c.status = LUA_YIELD; /* 'default' status */
- ci->callstatus |= CIST_YIELDED;
- lua_unlock(L);
- n = (*ci->u.c.k)(L); /* call continuation */
- lua_lock(L);
- api_checknelems(L, n);
- firstArg = L->top - n; /* yield results come from continuation */
- }
- luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
- }
- unroll(L, NULL);
- }
- lua_assert(nCcalls == L->nCcalls);
+ int nCcalls = L->nCcalls;
+ StkId firstArg = cast(StkId, ud);
+ CallInfo *ci = L->ci;
+ if (nCcalls >= LUAI_MAXCCALLS)
+ resume_error(L, "C stack overflow", firstArg);
+ if (L->status == LUA_OK) { /* may be starting a coroutine */
+ if (ci != &L->base_ci) /* not in base level? */
+ resume_error(L, "cannot resume non-suspended coroutine", firstArg);
+ /* coroutine is in base level; start running it */
+ if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */
+ luaV_execute(L); /* call it */
+ }
+ else if (L->status != LUA_YIELD)
+ resume_error(L, "cannot resume dead coroutine", firstArg);
+ else { /* resuming from previous yield */
+ L->status = LUA_OK;
+ ci->func = restorestack(L, ci->extra);
+ if (isLua(ci)) /* yielded inside a hook? */
+ luaV_execute(L); /* just continue running Lua code */
+ else { /* 'common' yield */
+ if (ci->u.c.k != NULL) { /* does it have a continuation? */
+ int n;
+ ci->u.c.status = LUA_YIELD; /* 'default' status */
+ ci->callstatus |= CIST_YIELDED;
+ lua_unlock(L);
+ n = (*ci->u.c.k)(L); /* call continuation */
+ lua_lock(L);
+ api_checknelems(L, n);
+ firstArg = L->top - n; /* yield results come from continuation */
+ }
+ luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
+ }
+ unroll(L, NULL);
+ }
+ lua_assert(nCcalls == L->nCcalls);
}
LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {
- int status;
- lua_lock(L);
- luai_userstateresume(L, nargs);
- L->nCcalls = (from) ? from->nCcalls + 1 : 1;
- L->nny = 0; /* allow yields */
- api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
- status = luaD_rawrunprotected(L, resume, L->top - nargs);
- if (status == -1) /* error calling 'lua_resume'? */
- status = LUA_ERRRUN;
- else { /* yield or regular error */
- while (status != LUA_OK && status != LUA_YIELD) { /* error? */
- if (recover(L, status)) /* recover point? */
- status = luaD_rawrunprotected(L, unroll, NULL); /* run continuation */
- else { /* unrecoverable error */
- L->status = cast_byte(status); /* mark thread as `dead' */
- seterrorobj(L, status, L->top);
- L->ci->top = L->top;
- break;
- }
- }
- lua_assert(status == L->status);
- }
- L->nny = 1; /* do not allow yields */
- L->nCcalls--;
- lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
- lua_unlock(L);
- return status;
+ int status;
+ lua_lock(L);
+ luai_userstateresume(L, nargs);
+ L->nCcalls = (from) ? from->nCcalls + 1 : 1;
+ L->nny = 0; /* allow yields */
+ api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
+ status = luaD_rawrunprotected(L, resume, L->top - nargs);
+ if (status == -1) /* error calling 'lua_resume'? */
+ status = LUA_ERRRUN;
+ else { /* yield or regular error */
+ while (status != LUA_OK && status != LUA_YIELD) { /* error? */
+ if (recover(L, status)) /* recover point? */
+ status = luaD_rawrunprotected(L, unroll, NULL); /* run continuation */
+ else { /* unrecoverable error */
+ L->status = cast_byte(status); /* mark thread as `dead' */
+ seterrorobj(L, status, L->top);
+ L->ci->top = L->top;
+ break;
+ }
+ }
+ lua_assert(status == L->status);
+ }
+ L->nny = 1; /* do not allow yields */
+ L->nCcalls--;
+ lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
+ lua_unlock(L);
+ return status;
}
LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) {
- CallInfo *ci = L->ci;
- luai_userstateyield(L, nresults);
- lua_lock(L);
- api_checknelems(L, nresults);
- if (L->nny > 0) {
- if (L != G(L)->mainthread)
- luaG_runerror(L, "attempt to yield across a C-call boundary");
- else
- luaG_runerror(L, "attempt to yield from outside a coroutine");
- }
- L->status = LUA_YIELD;
- ci->extra = savestack(L, ci->func); /* save current 'func' */
- if (isLua(ci)) { /* inside a hook? */
- api_check(L, k == NULL, "hooks cannot continue after yielding");
- }
- else {
- if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
- ci->u.c.ctx = ctx; /* save context */
- ci->func = L->top - nresults - 1; /* protect stack below results */
- luaD_throw(L, LUA_YIELD);
- }
- lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */
- lua_unlock(L);
- return 0; /* return to 'luaD_hook' */
+ CallInfo *ci = L->ci;
+ luai_userstateyield(L, nresults);
+ lua_lock(L);
+ api_checknelems(L, nresults);
+ if (L->nny > 0) {
+ if (L != G(L)->mainthread)
+ luaG_runerror(L, "attempt to yield across a C-call boundary");
+ else
+ luaG_runerror(L, "attempt to yield from outside a coroutine");
+ }
+ L->status = LUA_YIELD;
+ ci->extra = savestack(L, ci->func); /* save current 'func' */
+ if (isLua(ci)) { /* inside a hook? */
+ api_check(L, k == NULL, "hooks cannot continue after yielding");
+ }
+ else {
+ if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
+ ci->u.c.ctx = ctx; /* save context */
+ ci->func = L->top - nresults - 1; /* protect stack below results */
+ luaD_throw(L, LUA_YIELD);
+ }
+ lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */
+ lua_unlock(L);
+ return 0; /* return to 'luaD_hook' */
}
int luaD_pcall (lua_State *L, Pfunc func, void *u,
- ptrdiff_t old_top, ptrdiff_t ef) {
- int status;
- CallInfo *old_ci = L->ci;
- lu_byte old_allowhooks = L->allowhook;
- unsigned short old_nny = L->nny;
- ptrdiff_t old_errfunc = L->errfunc;
- L->errfunc = ef;
- status = luaD_rawrunprotected(L, func, u);
- if (status != LUA_OK) { /* an error occurred? */
- StkId oldtop = restorestack(L, old_top);
- luaF_close(L, oldtop); /* close possible pending closures */
- seterrorobj(L, status, oldtop);
- L->ci = old_ci;
- L->allowhook = old_allowhooks;
- L->nny = old_nny;
- luaD_shrinkstack(L);
- }
- L->errfunc = old_errfunc;
- return status;
+ ptrdiff_t old_top, ptrdiff_t ef) {
+ int status;
+ CallInfo *old_ci = L->ci;
+ lu_byte old_allowhooks = L->allowhook;
+ unsigned short old_nny = L->nny;
+ ptrdiff_t old_errfunc = L->errfunc;
+ L->errfunc = ef;
+ status = luaD_rawrunprotected(L, func, u);
+ if (status != LUA_OK) { /* an error occurred? */
+ StkId oldtop = restorestack(L, old_top);
+ luaF_close(L, oldtop); /* close possible pending closures */
+ seterrorobj(L, status, oldtop);
+ L->ci = old_ci;
+ L->allowhook = old_allowhooks;
+ L->nny = old_nny;
+ luaD_shrinkstack(L);
+ }
+ L->errfunc = old_errfunc;
+ return status;
}
@@ -612,62 +612,60 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
** Execute a protected parser.
*/
struct SParser { /* data to `f_parser' */
- ZIO *z;
- Mbuffer buff; /* dynamic structure used by the scanner */
- Dyndata dyd; /* dynamic structures used by the parser */
- const char *mode;
- const char *name;
+ ZIO *z;
+ Mbuffer buff; /* dynamic structure used by the scanner */
+ Dyndata dyd; /* dynamic structures used by the parser */
+ const char *mode;
+ const char *name;
};
static void checkmode (lua_State *L, const char *mode, const char *x) {
- if (mode && strchr(mode, x[0]) == NULL) {
- luaO_pushfstring(L,
- "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode);
- luaD_throw(L, LUA_ERRSYNTAX);
- }
+ if (mode && strchr(mode, x[0]) == NULL) {
+ luaO_pushfstring(L,
+ "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode);
+ luaD_throw(L, LUA_ERRSYNTAX);
+ }
}
static void f_parser (lua_State *L, void *ud) {
- int i;
- Closure *cl;
- struct SParser *p = cast(struct SParser *, ud);
- int c = zgetc(p->z); /* read first character */
- if (c == LUA_SIGNATURE[0]) {
- checkmode(L, p->mode, "binary");
- cl = luaU_undump(L, p->z, &p->buff, p->name);
- }
- else {
- checkmode(L, p->mode, "text");
- cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
- }
- lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
- for (i = 0; i < cl->l.nupvalues; i++) { /* initialize upvalues */
- UpVal *up = luaF_newupval(L);
- cl->l.upvals[i] = up;
- luaC_objbarrier(L, cl, up);
- }
+ int i;
+ Closure *cl;
+ struct SParser *p = cast(struct SParser *, ud);
+ int c = zgetc(p->z); /* read first character */
+ if (c == LUA_SIGNATURE[0]) {
+ checkmode(L, p->mode, "binary");
+ cl = luaU_undump(L, p->z, &p->buff, p->name);
+ }
+ else {
+ checkmode(L, p->mode, "text");
+ cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
+ }
+ lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
+ for (i = 0; i < cl->l.nupvalues; i++) { /* initialize upvalues */
+ UpVal *up = luaF_newupval(L);
+ cl->l.upvals[i] = up;
+ luaC_objbarrier(L, cl, up);
+ }
}
int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
- const char *mode) {
- struct SParser p;
- int status;
- L->nny++; /* cannot yield during parsing */
- p.z = z; p.name = name; p.mode = mode;
- p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;
- p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
- p.dyd.label.arr = NULL; p.dyd.label.size = 0;
- luaZ_initbuffer(L, &p.buff);
- status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
- luaZ_freebuffer(L, &p.buff);
- luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);
- luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);
- luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);
- L->nny--;
- return status;
+ const char *mode) {
+ struct SParser p;
+ int status;
+ L->nny++; /* cannot yield during parsing */
+ p.z = z; p.name = name; p.mode = mode;
+ p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;
+ p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
+ p.dyd.label.arr = NULL; p.dyd.label.size = 0;
+ luaZ_initbuffer(L, &p.buff);
+ status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
+ luaZ_freebuffer(L, &p.buff);
+ luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);
+ luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);
+ luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);
+ L->nny--;
+ return status;
}
-
-
diff --git a/src/lib/lua/ldo.h b/src/lib/lua/ldo.h
index 27b837d999e..fde866118d4 100644
--- a/src/lib/lua/ldo.h
+++ b/src/lib/lua/ldo.h
@@ -13,27 +13,27 @@
#include "lzio.h"
-#define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \
- luaD_growstack(L, n); else condmovestack(L);
+#define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \
+ luaD_growstack(L, n); else condmovestack(L);
#define incr_top(L) {L->top++; luaD_checkstack(L,0);}
-#define savestack(L,p) ((char *)(p) - (char *)L->stack)
-#define restorestack(L,n) ((TValue *)((char *)L->stack + (n)))
+#define savestack(L,p) ((char *)(p) - (char *)L->stack)
+#define restorestack(L,n) ((TValue *)((char *)L->stack + (n)))
/* type of protected functions, to be ran by `runprotected' */
typedef void (*Pfunc) (lua_State *L, void *ud);
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
- const char *mode);
+ const char *mode);
LUAI_FUNC void luaD_hook (lua_State *L, int event, int line);
LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);
LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults,
- int allowyield);
+ int allowyield);
LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
- ptrdiff_t oldtop, ptrdiff_t ef);
+ ptrdiff_t oldtop, ptrdiff_t ef);
LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
LUAI_FUNC void luaD_growstack (lua_State *L, int n);
@@ -43,4 +43,3 @@ LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
#endif
-
diff --git a/src/lib/lua/ldump.c b/src/lib/lua/ldump.c
index d5e6a47cb38..76c036e9854 100644
--- a/src/lib/lua/ldump.c
+++ b/src/lib/lua/ldump.c
@@ -16,144 +16,144 @@
#include "lundump.h"
typedef struct {
- lua_State* L;
- lua_Writer writer;
- void* data;
- int strip;
- int status;
+ lua_State* L;
+ lua_Writer writer;
+ void* data;
+ int strip;
+ int status;
} DumpState;
-#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
-#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
+#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
+#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
static void DumpBlock(const void* b, size_t size, DumpState* D)
{
- if (D->status==0)
- {
- lua_unlock(D->L);
- D->status=(*D->writer)(D->L,b,size,D->data);
- lua_lock(D->L);
- }
+ if (D->status==0)
+ {
+ lua_unlock(D->L);
+ D->status=(*D->writer)(D->L,b,size,D->data);
+ lua_lock(D->L);
+ }
}
static void DumpChar(int y, DumpState* D)
{
- char x=(char)y;
- DumpVar(x,D);
+ char x=(char)y;
+ DumpVar(x,D);
}
static void DumpInt(int x, DumpState* D)
{
- DumpVar(x,D);
+ DumpVar(x,D);
}
static void DumpNumber(lua_Number x, DumpState* D)
{
- DumpVar(x,D);
+ DumpVar(x,D);
}
static void DumpVector(const void* b, int n, size_t size, DumpState* D)
{
- DumpInt(n,D);
- DumpMem(b,n,size,D);
+ DumpInt(n,D);
+ DumpMem(b,n,size,D);
}
static void DumpString(const TString* s, DumpState* D)
{
- if (s==NULL)
- {
- size_t size=0;
- DumpVar(size,D);
- }
- else
- {
- size_t size=s->tsv.len+1; /* include trailing '\0' */
- DumpVar(size,D);
- DumpBlock(getstr(s),size*sizeof(char),D);
- }
+ if (s==NULL)
+ {
+ size_t size=0;
+ DumpVar(size,D);
+ }
+ else
+ {
+ size_t size=s->tsv.len+1; /* include trailing '\0' */
+ DumpVar(size,D);
+ DumpBlock(getstr(s),size*sizeof(char),D);
+ }
}
-#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
+#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
static void DumpFunction(const Proto* f, DumpState* D);
static void DumpConstants(const Proto* f, DumpState* D)
{
- int i,n=f->sizek;
- DumpInt(n,D);
- for (i=0; i<n; i++)
- {
- const TValue* o=&f->k[i];
- DumpChar(ttypenv(o),D);
- switch (ttypenv(o))
- {
- case LUA_TNIL:
+ int i,n=f->sizek;
+ DumpInt(n,D);
+ for (i=0; i<n; i++)
+ {
+ const TValue* o=&f->k[i];
+ DumpChar(ttypenv(o),D);
+ switch (ttypenv(o))
+ {
+ case LUA_TNIL:
break;
- case LUA_TBOOLEAN:
+ case LUA_TBOOLEAN:
DumpChar(bvalue(o),D);
break;
- case LUA_TNUMBER:
+ case LUA_TNUMBER:
DumpNumber(nvalue(o),D);
break;
- case LUA_TSTRING:
+ case LUA_TSTRING:
DumpString(rawtsvalue(o),D);
break;
- default: lua_assert(0);
- }
- }
- n=f->sizep;
- DumpInt(n,D);
- for (i=0; i<n; i++) DumpFunction(f->p[i],D);
+ default: lua_assert(0);
+ }
+ }
+ n=f->sizep;
+ DumpInt(n,D);
+ for (i=0; i<n; i++) DumpFunction(f->p[i],D);
}
static void DumpUpvalues(const Proto* f, DumpState* D)
{
- int i,n=f->sizeupvalues;
- DumpInt(n,D);
- for (i=0; i<n; i++)
- {
- DumpChar(f->upvalues[i].instack,D);
- DumpChar(f->upvalues[i].idx,D);
- }
+ int i,n=f->sizeupvalues;
+ DumpInt(n,D);
+ for (i=0; i<n; i++)
+ {
+ DumpChar(f->upvalues[i].instack,D);
+ DumpChar(f->upvalues[i].idx,D);
+ }
}
static void DumpDebug(const Proto* f, DumpState* D)
{
- int i,n;
- DumpString((D->strip) ? NULL : f->source,D);
- n= (D->strip) ? 0 : f->sizelineinfo;
- DumpVector(f->lineinfo,n,sizeof(int),D);
- n= (D->strip) ? 0 : f->sizelocvars;
- DumpInt(n,D);
- for (i=0; i<n; i++)
- {
- DumpString(f->locvars[i].varname,D);
- DumpInt(f->locvars[i].startpc,D);
- DumpInt(f->locvars[i].endpc,D);
- }
- n= (D->strip) ? 0 : f->sizeupvalues;
- DumpInt(n,D);
- for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);
+ int i,n;
+ DumpString((D->strip) ? NULL : f->source,D);
+ n= (D->strip) ? 0 : f->sizelineinfo;
+ DumpVector(f->lineinfo,n,sizeof(int),D);
+ n= (D->strip) ? 0 : f->sizelocvars;
+ DumpInt(n,D);
+ for (i=0; i<n; i++)
+ {
+ DumpString(f->locvars[i].varname,D);
+ DumpInt(f->locvars[i].startpc,D);
+ DumpInt(f->locvars[i].endpc,D);
+ }
+ n= (D->strip) ? 0 : f->sizeupvalues;
+ DumpInt(n,D);
+ for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);
}
static void DumpFunction(const Proto* f, DumpState* D)
{
- DumpInt(f->linedefined,D);
- DumpInt(f->lastlinedefined,D);
- DumpChar(f->numparams,D);
- DumpChar(f->is_vararg,D);
- DumpChar(f->maxstacksize,D);
- DumpCode(f,D);
- DumpConstants(f,D);
- DumpUpvalues(f,D);
- DumpDebug(f,D);
+ DumpInt(f->linedefined,D);
+ DumpInt(f->lastlinedefined,D);
+ DumpChar(f->numparams,D);
+ DumpChar(f->is_vararg,D);
+ DumpChar(f->maxstacksize,D);
+ DumpCode(f,D);
+ DumpConstants(f,D);
+ DumpUpvalues(f,D);
+ DumpDebug(f,D);
}
static void DumpHeader(DumpState* D)
{
- lu_byte h[LUAC_HEADERSIZE];
- luaU_header(h);
- DumpBlock(h,LUAC_HEADERSIZE,D);
+ lu_byte h[LUAC_HEADERSIZE];
+ luaU_header(h);
+ DumpBlock(h,LUAC_HEADERSIZE,D);
}
/*
@@ -161,13 +161,13 @@ static void DumpHeader(DumpState* D)
*/
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
{
- DumpState D;
- D.L=L;
- D.writer=w;
- D.data=data;
- D.strip=strip;
- D.status=0;
- DumpHeader(&D);
- DumpFunction(f,&D);
- return D.status;
+ DumpState D;
+ D.L=L;
+ D.writer=w;
+ D.data=data;
+ D.strip=strip;
+ D.status=0;
+ DumpHeader(&D);
+ DumpFunction(f,&D);
+ return D.status;
}
diff --git a/src/lib/lua/lfunc.c b/src/lib/lua/lfunc.c
index c2128405b9a..c34d657abcd 100644
--- a/src/lib/lua/lfunc.c
+++ b/src/lib/lua/lfunc.c
@@ -21,125 +21,125 @@
Closure *luaF_newCclosure (lua_State *L, int n) {
- Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
- c->c.nupvalues = cast_byte(n);
- return c;
+ Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
+ c->c.nupvalues = cast_byte(n);
+ return c;
}
Closure *luaF_newLclosure (lua_State *L, int n) {
- Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
- c->l.p = NULL;
- c->l.nupvalues = cast_byte(n);
- while (n--) c->l.upvals[n] = NULL;
- return c;
+ Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
+ c->l.p = NULL;
+ c->l.nupvalues = cast_byte(n);
+ while (n--) c->l.upvals[n] = NULL;
+ return c;
}
UpVal *luaF_newupval (lua_State *L) {
- UpVal *uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), NULL, 0)->uv;
- uv->v = &uv->u.value;
- setnilvalue(uv->v);
- return uv;
+ UpVal *uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), NULL, 0)->uv;
+ uv->v = &uv->u.value;
+ setnilvalue(uv->v);
+ return uv;
}
UpVal *luaF_findupval (lua_State *L, StkId level) {
- global_State *g = G(L);
- GCObject **pp = &L->openupval;
- UpVal *p;
- UpVal *uv;
- while (*pp != NULL && (p = gco2uv(*pp))->v >= level) {
- GCObject *o = obj2gco(p);
- lua_assert(p->v != &p->u.value);
- lua_assert(!isold(o) || isold(obj2gco(L)));
- if (p->v == level) { /* found a corresponding upvalue? */
- if (isdead(g, o)) /* is it dead? */
- changewhite(o); /* resurrect it */
- return p;
- }
- pp = &p->next;
- }
- /* not found: create a new one */
- uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), pp, 0)->uv;
- uv->v = level; /* current value lives in the stack */
- uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
- uv->u.l.next = g->uvhead.u.l.next;
- uv->u.l.next->u.l.prev = uv;
- g->uvhead.u.l.next = uv;
- lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
- return uv;
+ global_State *g = G(L);
+ GCObject **pp = &L->openupval;
+ UpVal *p;
+ UpVal *uv;
+ while (*pp != NULL && (p = gco2uv(*pp))->v >= level) {
+ GCObject *o = obj2gco(p);
+ lua_assert(p->v != &p->u.value);
+ lua_assert(!isold(o) || isold(obj2gco(L)));
+ if (p->v == level) { /* found a corresponding upvalue? */
+ if (isdead(g, o)) /* is it dead? */
+ changewhite(o); /* resurrect it */
+ return p;
+ }
+ pp = &p->next;
+ }
+ /* not found: create a new one */
+ uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), pp, 0)->uv;
+ uv->v = level; /* current value lives in the stack */
+ uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
+ uv->u.l.next = g->uvhead.u.l.next;
+ uv->u.l.next->u.l.prev = uv;
+ g->uvhead.u.l.next = uv;
+ lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
+ return uv;
}
static void unlinkupval (UpVal *uv) {
- lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
- uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */
- uv->u.l.prev->u.l.next = uv->u.l.next;
+ lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
+ uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */
+ uv->u.l.prev->u.l.next = uv->u.l.next;
}
void luaF_freeupval (lua_State *L, UpVal *uv) {
- if (uv->v != &uv->u.value) /* is it open? */
- unlinkupval(uv); /* remove from open list */
- luaM_free(L, uv); /* free upvalue */
+ if (uv->v != &uv->u.value) /* is it open? */
+ unlinkupval(uv); /* remove from open list */
+ luaM_free(L, uv); /* free upvalue */
}
void luaF_close (lua_State *L, StkId level) {
- UpVal *uv;
- global_State *g = G(L);
- while (L->openupval != NULL && (uv = gco2uv(L->openupval))->v >= level) {
- GCObject *o = obj2gco(uv);
- lua_assert(!isblack(o) && uv->v != &uv->u.value);
- L->openupval = uv->next; /* remove from `open' list */
- if (isdead(g, o))
- luaF_freeupval(L, uv); /* free upvalue */
- else {
- unlinkupval(uv); /* remove upvalue from 'uvhead' list */
- setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */
- uv->v = &uv->u.value; /* now current value lives here */
- gch(o)->next = g->allgc; /* link upvalue into 'allgc' list */
- g->allgc = o;
- luaC_checkupvalcolor(g, uv);
- }
- }
+ UpVal *uv;
+ global_State *g = G(L);
+ while (L->openupval != NULL && (uv = gco2uv(L->openupval))->v >= level) {
+ GCObject *o = obj2gco(uv);
+ lua_assert(!isblack(o) && uv->v != &uv->u.value);
+ L->openupval = uv->next; /* remove from `open' list */
+ if (isdead(g, o))
+ luaF_freeupval(L, uv); /* free upvalue */
+ else {
+ unlinkupval(uv); /* remove upvalue from 'uvhead' list */
+ setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */
+ uv->v = &uv->u.value; /* now current value lives here */
+ gch(o)->next = g->allgc; /* link upvalue into 'allgc' list */
+ g->allgc = o;
+ luaC_checkupvalcolor(g, uv);
+ }
+ }
}
Proto *luaF_newproto (lua_State *L) {
- Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), NULL, 0)->p;
- f->k = NULL;
- f->sizek = 0;
- f->p = NULL;
- f->sizep = 0;
- f->code = NULL;
- f->cache = NULL;
- f->sizecode = 0;
- f->lineinfo = NULL;
- f->sizelineinfo = 0;
- f->upvalues = NULL;
- f->sizeupvalues = 0;
- f->numparams = 0;
- f->is_vararg = 0;
- f->maxstacksize = 0;
- f->locvars = NULL;
- f->sizelocvars = 0;
- f->linedefined = 0;
- f->lastlinedefined = 0;
- f->source = NULL;
- return f;
+ Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), NULL, 0)->p;
+ f->k = NULL;
+ f->sizek = 0;
+ f->p = NULL;
+ f->sizep = 0;
+ f->code = NULL;
+ f->cache = NULL;
+ f->sizecode = 0;
+ f->lineinfo = NULL;
+ f->sizelineinfo = 0;
+ f->upvalues = NULL;
+ f->sizeupvalues = 0;
+ f->numparams = 0;
+ f->is_vararg = 0;
+ f->maxstacksize = 0;
+ f->locvars = NULL;
+ f->sizelocvars = 0;
+ f->linedefined = 0;
+ f->lastlinedefined = 0;
+ f->source = NULL;
+ return f;
}
void luaF_freeproto (lua_State *L, Proto *f) {
- luaM_freearray(L, f->code, f->sizecode);
- luaM_freearray(L, f->p, f->sizep);
- luaM_freearray(L, f->k, f->sizek);
- luaM_freearray(L, f->lineinfo, f->sizelineinfo);
- luaM_freearray(L, f->locvars, f->sizelocvars);
- luaM_freearray(L, f->upvalues, f->sizeupvalues);
- luaM_free(L, f);
+ luaM_freearray(L, f->code, f->sizecode);
+ luaM_freearray(L, f->p, f->sizep);
+ luaM_freearray(L, f->k, f->sizek);
+ luaM_freearray(L, f->lineinfo, f->sizelineinfo);
+ luaM_freearray(L, f->locvars, f->sizelocvars);
+ luaM_freearray(L, f->upvalues, f->sizeupvalues);
+ luaM_free(L, f);
}
@@ -148,14 +148,13 @@ void luaF_freeproto (lua_State *L, Proto *f) {
** Returns NULL if not found.
*/
const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
- int i;
- for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
- if (pc < f->locvars[i].endpc) { /* is variable active? */
- local_number--;
- if (local_number == 0)
- return getstr(f->locvars[i].varname);
- }
- }
- return NULL; /* not found */
+ int i;
+ for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
+ if (pc < f->locvars[i].endpc) { /* is variable active? */
+ local_number--;
+ if (local_number == 0)
+ return getstr(f->locvars[i].varname);
+ }
+ }
+ return NULL; /* not found */
}
-
diff --git a/src/lib/lua/lfunc.h b/src/lib/lua/lfunc.h
index e236a717c65..563ffe520f3 100644
--- a/src/lib/lua/lfunc.h
+++ b/src/lib/lua/lfunc.h
@@ -11,11 +11,11 @@
#include "lobject.h"
-#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
- cast(int, sizeof(TValue)*((n)-1)))
+#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
+ cast(int, sizeof(TValue)*((n)-1)))
-#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
- cast(int, sizeof(TValue *)*((n)-1)))
+#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
+ cast(int, sizeof(TValue *)*((n)-1)))
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
@@ -27,7 +27,7 @@ LUAI_FUNC void luaF_close (lua_State *L, StkId level);
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
- int pc);
+ int pc);
#endif
diff --git a/src/lib/lua/lgc.c b/src/lib/lua/lgc.c
index 535e988ae02..ca8e881f575 100644
--- a/src/lib/lua/lgc.c
+++ b/src/lib/lua/lgc.c
@@ -28,52 +28,52 @@
** cost of sweeping one element (the size of a small object divided
** by some adjust for the sweep speed)
*/
-#define GCSWEEPCOST ((sizeof(TString) + 4) / 4)
+#define GCSWEEPCOST ((sizeof(TString) + 4) / 4)
/* maximum number of elements to sweep in each single step */
-#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))
+#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))
/* maximum number of finalizers to call in each GC step */
-#define GCFINALIZENUM 4
+#define GCFINALIZENUM 4
/*
** macro to adjust 'stepmul': 'stepmul' is actually used like
** 'stepmul / STEPMULADJ' (value chosen by tests)
*/
-#define STEPMULADJ 200
+#define STEPMULADJ 200
/*
** macro to adjust 'pause': 'pause' is actually used like
** 'pause / PAUSEADJ' (value chosen by tests)
*/
-#define PAUSEADJ 100
+#define PAUSEADJ 100
/*
** 'makewhite' erases all color bits plus the old bit and then
** sets only the current white bit
*/
-#define maskcolors (~(bit2mask(BLACKBIT, OLDBIT) | WHITEBITS))
-#define makewhite(g,x) \
- (gch(x)->marked = cast_byte((gch(x)->marked & maskcolors) | luaC_white(g)))
+#define maskcolors (~(bit2mask(BLACKBIT, OLDBIT) | WHITEBITS))
+#define makewhite(g,x) \
+ (gch(x)->marked = cast_byte((gch(x)->marked & maskcolors) | luaC_white(g)))
-#define white2gray(x) resetbits(gch(x)->marked, WHITEBITS)
-#define black2gray(x) resetbit(gch(x)->marked, BLACKBIT)
+#define white2gray(x) resetbits(gch(x)->marked, WHITEBITS)
+#define black2gray(x) resetbit(gch(x)->marked, BLACKBIT)
-#define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT)
+#define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT)
-#define checkdeadkey(n) lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))
+#define checkdeadkey(n) lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))
#define checkconsistency(obj) \
- lua_longassert(!iscollectable(obj) || righttt(obj))
+ lua_longassert(!iscollectable(obj) || righttt(obj))
#define markvalue(g,o) { checkconsistency(o); \
- if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }
+ if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }
#define markobject(g,t) { if ((t) && iswhite(obj2gco(t))) \
reallymarkobject(g, obj2gco(t)); }
@@ -91,13 +91,13 @@ static void reallymarkobject (global_State *g, GCObject *o);
/*
** one after last element in a hash array
*/
-#define gnodelast(h) gnode(h, cast(size_t, sizenode(h)))
+#define gnodelast(h) gnode(h, cast(size_t, sizenode(h)))
/*
** link table 'h' into list pointed by 'p'
*/
-#define linktable(h,p) ((h)->gclist = *(p), *(p) = obj2gco(h))
+#define linktable(h,p) ((h)->gclist = *(p), *(p) = obj2gco(h))
/*
@@ -105,9 +105,9 @@ static void reallymarkobject (global_State *g, GCObject *o);
** from the table)
*/
static void removeentry (Node *n) {
- lua_assert(ttisnil(gval(n)));
- if (valiswhite(gkey(n)))
- setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */
+ lua_assert(ttisnil(gval(n)));
+ if (valiswhite(gkey(n)))
+ setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */
}
@@ -119,12 +119,12 @@ static void removeentry (Node *n) {
** being finalized, keep them in keys, but not in values
*/
static int iscleared (global_State *g, const TValue *o) {
- if (!iscollectable(o)) return 0;
- else if (ttisstring(o)) {
- markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */
- return 0;
- }
- else return iswhite(gcvalue(o));
+ if (!iscollectable(o)) return 0;
+ else if (ttisstring(o)) {
+ markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */
+ return 0;
+ }
+ else return iswhite(gcvalue(o));
}
@@ -133,16 +133,16 @@ static int iscleared (global_State *g, const TValue *o) {
** being pointed by a black object.
*/
void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
- global_State *g = G(L);
- lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
- lua_assert(g->gcstate != GCSpause);
- lua_assert(gch(o)->tt != LUA_TTABLE);
- if (keepinvariantout(g)) /* must keep invariant? */
- reallymarkobject(g, v); /* restore invariant */
- else { /* sweep phase */
- lua_assert(issweepphase(g));
- makewhite(g, o); /* mark main obj. as white to avoid other barriers */
- }
+ global_State *g = G(L);
+ lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
+ lua_assert(g->gcstate != GCSpause);
+ lua_assert(gch(o)->tt != LUA_TTABLE);
+ if (keepinvariantout(g)) /* must keep invariant? */
+ reallymarkobject(g, v); /* restore invariant */
+ else { /* sweep phase */
+ lua_assert(issweepphase(g));
+ makewhite(g, o); /* mark main obj. as white to avoid other barriers */
+ }
}
@@ -153,11 +153,11 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
** different types.)
*/
void luaC_barrierback_ (lua_State *L, GCObject *o) {
- global_State *g = G(L);
- lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE);
- black2gray(o); /* make object gray (again) */
- gco2t(o)->gclist = g->grayagain;
- g->grayagain = o;
+ global_State *g = G(L);
+ lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE);
+ black2gray(o); /* make object gray (again) */
+ gco2t(o)->gclist = g->grayagain;
+ g->grayagain = o;
}
@@ -170,16 +170,16 @@ void luaC_barrierback_ (lua_State *L, GCObject *o) {
** possible instances.
*/
LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c) {
- global_State *g = G(L);
- lua_assert(isblack(obj2gco(p)));
- if (p->cache == NULL) { /* first time? */
- luaC_objbarrier(L, p, c);
- }
- else { /* use a backward barrier */
- black2gray(obj2gco(p)); /* make prototype gray (again) */
- p->gclist = g->grayagain;
- g->grayagain = obj2gco(p);
- }
+ global_State *g = G(L);
+ lua_assert(isblack(obj2gco(p)));
+ if (p->cache == NULL) { /* first time? */
+ luaC_objbarrier(L, p, c);
+ }
+ else { /* use a backward barrier */
+ black2gray(obj2gco(p)); /* make prototype gray (again) */
+ p->gclist = g->grayagain;
+ g->grayagain = obj2gco(p);
+ }
}
@@ -188,19 +188,19 @@ LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c) {
** i.e., moved into the 'allgc' list
*/
void luaC_checkupvalcolor (global_State *g, UpVal *uv) {
- GCObject *o = obj2gco(uv);
- lua_assert(!isblack(o)); /* open upvalues are never black */
- if (isgray(o)) {
- if (keepinvariant(g)) {
- resetoldbit(o); /* see MOVE OLD rule */
- gray2black(o); /* it is being visited now */
- markvalue(g, uv->v);
- }
- else {
- lua_assert(issweepphase(g));
- makewhite(g, o);
- }
- }
+ GCObject *o = obj2gco(uv);
+ lua_assert(!isblack(o)); /* open upvalues are never black */
+ if (isgray(o)) {
+ if (keepinvariant(g)) {
+ resetoldbit(o); /* see MOVE OLD rule */
+ gray2black(o); /* it is being visited now */
+ markvalue(g, uv->v);
+ }
+ else {
+ lua_assert(issweepphase(g));
+ makewhite(g, o);
+ }
+ }
}
@@ -210,17 +210,17 @@ void luaC_checkupvalcolor (global_State *g, UpVal *uv) {
** object itself (used only by states).
*/
GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
- int offset) {
- global_State *g = G(L);
- char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
- GCObject *o = obj2gco(raw + offset);
- if (list == NULL)
- list = &g->allgc; /* standard list for collectable objects */
- gch(o)->marked = luaC_white(g);
- gch(o)->tt = tt;
- gch(o)->next = *list;
- *list = o;
- return o;
+ int offset) {
+ global_State *g = G(L);
+ char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
+ GCObject *o = obj2gco(raw + offset);
+ if (list == NULL)
+ list = &g->allgc; /* standard list for collectable objects */
+ gch(o)->marked = luaC_white(g);
+ gch(o)->tt = tt;
+ gch(o)->next = *list;
+ *list = o;
+ return o;
}
/* }====================================================== */
@@ -241,57 +241,57 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
** upvalues are already linked in 'headuv' list.)
*/
static void reallymarkobject (global_State *g, GCObject *o) {
- lu_mem size;
- white2gray(o);
- switch (gch(o)->tt) {
- case LUA_TSHRSTR:
- case LUA_TLNGSTR: {
- size = sizestring(gco2ts(o));
- break; /* nothing else to mark; make it black */
- }
- case LUA_TUSERDATA: {
- Table *mt = gco2u(o)->metatable;
- markobject(g, mt);
- markobject(g, gco2u(o)->env);
- size = sizeudata(gco2u(o));
- break;
- }
- case LUA_TUPVAL: {
- UpVal *uv = gco2uv(o);
- markvalue(g, uv->v);
- if (uv->v != &uv->u.value) /* open? */
- return; /* open upvalues remain gray */
- size = sizeof(UpVal);
- break;
- }
- case LUA_TLCL: {
- gco2lcl(o)->gclist = g->gray;
- g->gray = o;
- return;
- }
- case LUA_TCCL: {
- gco2ccl(o)->gclist = g->gray;
- g->gray = o;
- return;
- }
- case LUA_TTABLE: {
- linktable(gco2t(o), &g->gray);
- return;
- }
- case LUA_TTHREAD: {
- gco2th(o)->gclist = g->gray;
- g->gray = o;
- return;
- }
- case LUA_TPROTO: {
- gco2p(o)->gclist = g->gray;
- g->gray = o;
- return;
- }
- default: lua_assert(0); return;
- }
- gray2black(o);
- g->GCmemtrav += size;
+ lu_mem size;
+ white2gray(o);
+ switch (gch(o)->tt) {
+ case LUA_TSHRSTR:
+ case LUA_TLNGSTR: {
+ size = sizestring(gco2ts(o));
+ break; /* nothing else to mark; make it black */
+ }
+ case LUA_TUSERDATA: {
+ Table *mt = gco2u(o)->metatable;
+ markobject(g, mt);
+ markobject(g, gco2u(o)->env);
+ size = sizeudata(gco2u(o));
+ break;
+ }
+ case LUA_TUPVAL: {
+ UpVal *uv = gco2uv(o);
+ markvalue(g, uv->v);
+ if (uv->v != &uv->u.value) /* open? */
+ return; /* open upvalues remain gray */
+ size = sizeof(UpVal);
+ break;
+ }
+ case LUA_TLCL: {
+ gco2lcl(o)->gclist = g->gray;
+ g->gray = o;
+ return;
+ }
+ case LUA_TCCL: {
+ gco2ccl(o)->gclist = g->gray;
+ g->gray = o;
+ return;
+ }
+ case LUA_TTABLE: {
+ linktable(gco2t(o), &g->gray);
+ return;
+ }
+ case LUA_TTHREAD: {
+ gco2th(o)->gclist = g->gray;
+ g->gray = o;
+ return;
+ }
+ case LUA_TPROTO: {
+ gco2p(o)->gclist = g->gray;
+ g->gray = o;
+ return;
+ }
+ default: lua_assert(0); return;
+ }
+ gray2black(o);
+ g->GCmemtrav += size;
}
@@ -299,9 +299,9 @@ static void reallymarkobject (global_State *g, GCObject *o) {
** mark metamethods for basic types
*/
static void markmt (global_State *g) {
- int i;
- for (i=0; i < LUA_NUMTAGS; i++)
- markobject(g, g->mt[i]);
+ int i;
+ for (i=0; i < LUA_NUMTAGS; i++)
+ markobject(g, g->mt[i]);
}
@@ -309,11 +309,11 @@ static void markmt (global_State *g) {
** mark all objects in list of being-finalized
*/
static void markbeingfnz (global_State *g) {
- GCObject *o;
- for (o = g->tobefnz; o != NULL; o = gch(o)->next) {
- makewhite(g, o);
- reallymarkobject(g, o);
- }
+ GCObject *o;
+ for (o = g->tobefnz; o != NULL; o = gch(o)->next) {
+ makewhite(g, o);
+ reallymarkobject(g, o);
+ }
}
@@ -322,11 +322,11 @@ static void markbeingfnz (global_State *g) {
** 'lstate.h'.)
*/
static void remarkupvals (global_State *g) {
- UpVal *uv;
- for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {
- if (isgray(obj2gco(uv)))
- markvalue(g, uv->v);
- }
+ UpVal *uv;
+ for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {
+ if (isgray(obj2gco(uv)))
+ markvalue(g, uv->v);
+ }
}
@@ -335,12 +335,12 @@ static void remarkupvals (global_State *g) {
** incremental (or full) collection
*/
static void restartcollection (global_State *g) {
- g->gray = g->grayagain = NULL;
- g->weak = g->allweak = g->ephemeron = NULL;
- markobject(g, g->mainthread);
- markvalue(g, &g->l_registry);
- markmt(g);
- markbeingfnz(g); /* mark any finalizing object left from previous cycle */
+ g->gray = g->grayagain = NULL;
+ g->weak = g->allweak = g->ephemeron = NULL;
+ markobject(g, g->mainthread);
+ markvalue(g, &g->l_registry);
+ markmt(g);
+ markbeingfnz(g); /* mark any finalizing object left from previous cycle */
}
/* }====================================================== */
@@ -353,157 +353,157 @@ static void restartcollection (global_State *g) {
*/
static void traverseweakvalue (global_State *g, Table *h) {
- Node *n, *limit = gnodelast(h);
- /* if there is array part, assume it may have white values (do not
- traverse it just to check) */
- int hasclears = (h->sizearray > 0);
- for (n = gnode(h, 0); n < limit; n++) {
- checkdeadkey(n);
- if (ttisnil(gval(n))) /* entry is empty? */
- removeentry(n); /* remove it */
- else {
- lua_assert(!ttisnil(gkey(n)));
- markvalue(g, gkey(n)); /* mark key */
- if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */
- hasclears = 1; /* table will have to be cleared */
- }
- }
- if (hasclears)
- linktable(h, &g->weak); /* has to be cleared later */
- else /* no white values */
- linktable(h, &g->grayagain); /* no need to clean */
+ Node *n, *limit = gnodelast(h);
+ /* if there is array part, assume it may have white values (do not
+ traverse it just to check) */
+ int hasclears = (h->sizearray > 0);
+ for (n = gnode(h, 0); n < limit; n++) {
+ checkdeadkey(n);
+ if (ttisnil(gval(n))) /* entry is empty? */
+ removeentry(n); /* remove it */
+ else {
+ lua_assert(!ttisnil(gkey(n)));
+ markvalue(g, gkey(n)); /* mark key */
+ if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */
+ hasclears = 1; /* table will have to be cleared */
+ }
+ }
+ if (hasclears)
+ linktable(h, &g->weak); /* has to be cleared later */
+ else /* no white values */
+ linktable(h, &g->grayagain); /* no need to clean */
}
static int traverseephemeron (global_State *g, Table *h) {
- int marked = 0; /* true if an object is marked in this traversal */
- int hasclears = 0; /* true if table has white keys */
- int prop = 0; /* true if table has entry "white-key -> white-value" */
- Node *n, *limit = gnodelast(h);
- int i;
- /* traverse array part (numeric keys are 'strong') */
- for (i = 0; i < h->sizearray; i++) {
- if (valiswhite(&h->array[i])) {
- marked = 1;
- reallymarkobject(g, gcvalue(&h->array[i]));
- }
- }
- /* traverse hash part */
- for (n = gnode(h, 0); n < limit; n++) {
- checkdeadkey(n);
- if (ttisnil(gval(n))) /* entry is empty? */
- removeentry(n); /* remove it */
- else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */
- hasclears = 1; /* table must be cleared */
- if (valiswhite(gval(n))) /* value not marked yet? */
- prop = 1; /* must propagate again */
- }
- else if (valiswhite(gval(n))) { /* value not marked yet? */
- marked = 1;
- reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
- }
- }
- if (prop)
- linktable(h, &g->ephemeron); /* have to propagate again */
- else if (hasclears) /* does table have white keys? */
- linktable(h, &g->allweak); /* may have to clean white keys */
- else /* no white keys */
- linktable(h, &g->grayagain); /* no need to clean */
- return marked;
+ int marked = 0; /* true if an object is marked in this traversal */
+ int hasclears = 0; /* true if table has white keys */
+ int prop = 0; /* true if table has entry "white-key -> white-value" */
+ Node *n, *limit = gnodelast(h);
+ int i;
+ /* traverse array part (numeric keys are 'strong') */
+ for (i = 0; i < h->sizearray; i++) {
+ if (valiswhite(&h->array[i])) {
+ marked = 1;
+ reallymarkobject(g, gcvalue(&h->array[i]));
+ }
+ }
+ /* traverse hash part */
+ for (n = gnode(h, 0); n < limit; n++) {
+ checkdeadkey(n);
+ if (ttisnil(gval(n))) /* entry is empty? */
+ removeentry(n); /* remove it */
+ else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */
+ hasclears = 1; /* table must be cleared */
+ if (valiswhite(gval(n))) /* value not marked yet? */
+ prop = 1; /* must propagate again */
+ }
+ else if (valiswhite(gval(n))) { /* value not marked yet? */
+ marked = 1;
+ reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
+ }
+ }
+ if (prop)
+ linktable(h, &g->ephemeron); /* have to propagate again */
+ else if (hasclears) /* does table have white keys? */
+ linktable(h, &g->allweak); /* may have to clean white keys */
+ else /* no white keys */
+ linktable(h, &g->grayagain); /* no need to clean */
+ return marked;
}
static void traversestrongtable (global_State *g, Table *h) {
- Node *n, *limit = gnodelast(h);
- int i;
- for (i = 0; i < h->sizearray; i++) /* traverse array part */
- markvalue(g, &h->array[i]);
- for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */
- checkdeadkey(n);
- if (ttisnil(gval(n))) /* entry is empty? */
- removeentry(n); /* remove it */
- else {
- lua_assert(!ttisnil(gkey(n)));
- markvalue(g, gkey(n)); /* mark key */
- markvalue(g, gval(n)); /* mark value */
- }
- }
+ Node *n, *limit = gnodelast(h);
+ int i;
+ for (i = 0; i < h->sizearray; i++) /* traverse array part */
+ markvalue(g, &h->array[i]);
+ for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */
+ checkdeadkey(n);
+ if (ttisnil(gval(n))) /* entry is empty? */
+ removeentry(n); /* remove it */
+ else {
+ lua_assert(!ttisnil(gkey(n)));
+ markvalue(g, gkey(n)); /* mark key */
+ markvalue(g, gval(n)); /* mark value */
+ }
+ }
}
static lu_mem traversetable (global_State *g, Table *h) {
- const char *weakkey, *weakvalue;
- const TValue *mode = gfasttm(g, h->metatable, TM_MODE);
- markobject(g, h->metatable);
- if (mode && ttisstring(mode) && /* is there a weak mode? */
- ((weakkey = strchr(svalue(mode), 'k')),
- (weakvalue = strchr(svalue(mode), 'v')),
- (weakkey || weakvalue))) { /* is really weak? */
- black2gray(obj2gco(h)); /* keep table gray */
- if (!weakkey) /* strong keys? */
- traverseweakvalue(g, h);
- else if (!weakvalue) /* strong values? */
- traverseephemeron(g, h);
- else /* all weak */
- linktable(h, &g->allweak); /* nothing to traverse now */
- }
- else /* not weak */
- traversestrongtable(g, h);
- return sizeof(Table) + sizeof(TValue) * h->sizearray +
- sizeof(Node) * cast(size_t, sizenode(h));
+ const char *weakkey, *weakvalue;
+ const TValue *mode = gfasttm(g, h->metatable, TM_MODE);
+ markobject(g, h->metatable);
+ if (mode && ttisstring(mode) && /* is there a weak mode? */
+ ((weakkey = strchr(svalue(mode), 'k')),
+ (weakvalue = strchr(svalue(mode), 'v')),
+ (weakkey || weakvalue))) { /* is really weak? */
+ black2gray(obj2gco(h)); /* keep table gray */
+ if (!weakkey) /* strong keys? */
+ traverseweakvalue(g, h);
+ else if (!weakvalue) /* strong values? */
+ traverseephemeron(g, h);
+ else /* all weak */
+ linktable(h, &g->allweak); /* nothing to traverse now */
+ }
+ else /* not weak */
+ traversestrongtable(g, h);
+ return sizeof(Table) + sizeof(TValue) * h->sizearray +
+ sizeof(Node) * cast(size_t, sizenode(h));
}
static int traverseproto (global_State *g, Proto *f) {
- int i;
- if (f->cache && iswhite(obj2gco(f->cache)))
- f->cache = NULL; /* allow cache to be collected */
- markobject(g, f->source);
- for (i = 0; i < f->sizek; i++) /* mark literals */
- markvalue(g, &f->k[i]);
- for (i = 0; i < f->sizeupvalues; i++) /* mark upvalue names */
- markobject(g, f->upvalues[i].name);
- for (i = 0; i < f->sizep; i++) /* mark nested protos */
- markobject(g, f->p[i]);
- for (i = 0; i < f->sizelocvars; i++) /* mark local-variable names */
- markobject(g, f->locvars[i].varname);
- return sizeof(Proto) + sizeof(Instruction) * f->sizecode +
- sizeof(Proto *) * f->sizep +
- sizeof(TValue) * f->sizek +
- sizeof(int) * f->sizelineinfo +
- sizeof(LocVar) * f->sizelocvars +
- sizeof(Upvaldesc) * f->sizeupvalues;
+ int i;
+ if (f->cache && iswhite(obj2gco(f->cache)))
+ f->cache = NULL; /* allow cache to be collected */
+ markobject(g, f->source);
+ for (i = 0; i < f->sizek; i++) /* mark literals */
+ markvalue(g, &f->k[i]);
+ for (i = 0; i < f->sizeupvalues; i++) /* mark upvalue names */
+ markobject(g, f->upvalues[i].name);
+ for (i = 0; i < f->sizep; i++) /* mark nested protos */
+ markobject(g, f->p[i]);
+ for (i = 0; i < f->sizelocvars; i++) /* mark local-variable names */
+ markobject(g, f->locvars[i].varname);
+ return sizeof(Proto) + sizeof(Instruction) * f->sizecode +
+ sizeof(Proto *) * f->sizep +
+ sizeof(TValue) * f->sizek +
+ sizeof(int) * f->sizelineinfo +
+ sizeof(LocVar) * f->sizelocvars +
+ sizeof(Upvaldesc) * f->sizeupvalues;
}
static lu_mem traverseCclosure (global_State *g, CClosure *cl) {
- int i;
- for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
- markvalue(g, &cl->upvalue[i]);
- return sizeCclosure(cl->nupvalues);
+ int i;
+ for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
+ markvalue(g, &cl->upvalue[i]);
+ return sizeCclosure(cl->nupvalues);
}
static lu_mem traverseLclosure (global_State *g, LClosure *cl) {
- int i;
- markobject(g, cl->p); /* mark its prototype */
- for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
- markobject(g, cl->upvals[i]);
- return sizeLclosure(cl->nupvalues);
+ int i;
+ markobject(g, cl->p); /* mark its prototype */
+ for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
+ markobject(g, cl->upvals[i]);
+ return sizeLclosure(cl->nupvalues);
}
static lu_mem traversestack (global_State *g, lua_State *th) {
- StkId o = th->stack;
- if (o == NULL)
- return 1; /* stack not completely built yet */
- for (; o < th->top; o++)
- markvalue(g, o);
- if (g->gcstate == GCSatomic) { /* final traversal? */
- StkId lim = th->stack + th->stacksize; /* real end of stack */
- for (; o < lim; o++) /* clear not-marked stack slice */
- setnilvalue(o);
- }
- return sizeof(lua_State) + sizeof(TValue) * th->stacksize;
+ StkId o = th->stack;
+ if (o == NULL)
+ return 1; /* stack not completely built yet */
+ for (; o < th->top; o++)
+ markvalue(g, o);
+ if (g->gcstate == GCSatomic) { /* final traversal? */
+ StkId lim = th->stack + th->stacksize; /* real end of stack */
+ for (; o < lim; o++) /* clear not-marked stack slice */
+ setnilvalue(o);
+ }
+ return sizeof(lua_State) + sizeof(TValue) * th->stacksize;
}
@@ -512,59 +512,59 @@ static lu_mem traversestack (global_State *g, lua_State *th) {
** which are always gray).
*/
static void propagatemark (global_State *g) {
- lu_mem size;
- GCObject *o = g->gray;
- lua_assert(isgray(o));
- gray2black(o);
- switch (gch(o)->tt) {
- case LUA_TTABLE: {
- Table *h = gco2t(o);
- g->gray = h->gclist; /* remove from 'gray' list */
- size = traversetable(g, h);
- break;
- }
- case LUA_TLCL: {
- LClosure *cl = gco2lcl(o);
- g->gray = cl->gclist; /* remove from 'gray' list */
- size = traverseLclosure(g, cl);
- break;
- }
- case LUA_TCCL: {
- CClosure *cl = gco2ccl(o);
- g->gray = cl->gclist; /* remove from 'gray' list */
- size = traverseCclosure(g, cl);
- break;
- }
- case LUA_TTHREAD: {
- lua_State *th = gco2th(o);
- g->gray = th->gclist; /* remove from 'gray' list */
- th->gclist = g->grayagain;
- g->grayagain = o; /* insert into 'grayagain' list */
- black2gray(o);
- size = traversestack(g, th);
- break;
- }
- case LUA_TPROTO: {
- Proto *p = gco2p(o);
- g->gray = p->gclist; /* remove from 'gray' list */
- size = traverseproto(g, p);
- break;
- }
- default: lua_assert(0); return;
- }
- g->GCmemtrav += size;
+ lu_mem size;
+ GCObject *o = g->gray;
+ lua_assert(isgray(o));
+ gray2black(o);
+ switch (gch(o)->tt) {
+ case LUA_TTABLE: {
+ Table *h = gco2t(o);
+ g->gray = h->gclist; /* remove from 'gray' list */
+ size = traversetable(g, h);
+ break;
+ }
+ case LUA_TLCL: {
+ LClosure *cl = gco2lcl(o);
+ g->gray = cl->gclist; /* remove from 'gray' list */
+ size = traverseLclosure(g, cl);
+ break;
+ }
+ case LUA_TCCL: {
+ CClosure *cl = gco2ccl(o);
+ g->gray = cl->gclist; /* remove from 'gray' list */
+ size = traverseCclosure(g, cl);
+ break;
+ }
+ case LUA_TTHREAD: {
+ lua_State *th = gco2th(o);
+ g->gray = th->gclist; /* remove from 'gray' list */
+ th->gclist = g->grayagain;
+ g->grayagain = o; /* insert into 'grayagain' list */
+ black2gray(o);
+ size = traversestack(g, th);
+ break;
+ }
+ case LUA_TPROTO: {
+ Proto *p = gco2p(o);
+ g->gray = p->gclist; /* remove from 'gray' list */
+ size = traverseproto(g, p);
+ break;
+ }
+ default: lua_assert(0); return;
+ }
+ g->GCmemtrav += size;
}
static void propagateall (global_State *g) {
- while (g->gray) propagatemark(g);
+ while (g->gray) propagatemark(g);
}
static void propagatelist (global_State *g, GCObject *l) {
- lua_assert(g->gray == NULL); /* no grays left */
- g->gray = l;
- propagateall(g); /* traverse all elements from 'l' */
+ lua_assert(g->gray == NULL); /* no grays left */
+ g->gray = l;
+ propagateall(g); /* traverse all elements from 'l' */
}
/*
@@ -573,32 +573,32 @@ static void propagatelist (global_State *g, GCObject *l) {
** twice the same table (which is not wrong, but inefficient)
*/
static void retraversegrays (global_State *g) {
- GCObject *weak = g->weak; /* save original lists */
- GCObject *grayagain = g->grayagain;
- GCObject *ephemeron = g->ephemeron;
- g->weak = g->grayagain = g->ephemeron = NULL;
- propagateall(g); /* traverse main gray list */
- propagatelist(g, grayagain);
- propagatelist(g, weak);
- propagatelist(g, ephemeron);
+ GCObject *weak = g->weak; /* save original lists */
+ GCObject *grayagain = g->grayagain;
+ GCObject *ephemeron = g->ephemeron;
+ g->weak = g->grayagain = g->ephemeron = NULL;
+ propagateall(g); /* traverse main gray list */
+ propagatelist(g, grayagain);
+ propagatelist(g, weak);
+ propagatelist(g, ephemeron);
}
static void convergeephemerons (global_State *g) {
- int changed;
- do {
- GCObject *w;
- GCObject *next = g->ephemeron; /* get ephemeron list */
- g->ephemeron = NULL; /* tables will return to this list when traversed */
- changed = 0;
- while ((w = next) != NULL) {
- next = gco2t(w)->gclist;
- if (traverseephemeron(g, gco2t(w))) { /* traverse marked some value? */
- propagateall(g); /* propagate changes */
- changed = 1; /* will have to revisit all ephemeron tables */
- }
- }
- } while (changed);
+ int changed;
+ do {
+ GCObject *w;
+ GCObject *next = g->ephemeron; /* get ephemeron list */
+ g->ephemeron = NULL; /* tables will return to this list when traversed */
+ changed = 0;
+ while ((w = next) != NULL) {
+ next = gco2t(w)->gclist;
+ if (traverseephemeron(g, gco2t(w))) { /* traverse marked some value? */
+ propagateall(g); /* propagate changes */
+ changed = 1; /* will have to revisit all ephemeron tables */
+ }
+ }
+ } while (changed);
}
/* }====================================================== */
@@ -616,16 +616,16 @@ static void convergeephemerons (global_State *g) {
** to element 'f'
*/
static void clearkeys (global_State *g, GCObject *l, GCObject *f) {
- for (; l != f; l = gco2t(l)->gclist) {
- Table *h = gco2t(l);
- Node *n, *limit = gnodelast(h);
- for (n = gnode(h, 0); n < limit; n++) {
- if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {
- setnilvalue(gval(n)); /* remove value ... */
- removeentry(n); /* and remove entry from table */
- }
- }
- }
+ for (; l != f; l = gco2t(l)->gclist) {
+ Table *h = gco2t(l);
+ Node *n, *limit = gnodelast(h);
+ for (n = gnode(h, 0); n < limit; n++) {
+ if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {
+ setnilvalue(gval(n)); /* remove value ... */
+ removeentry(n); /* and remove entry from table */
+ }
+ }
+ }
}
@@ -634,53 +634,53 @@ static void clearkeys (global_State *g, GCObject *l, GCObject *f) {
** to element 'f'
*/
static void clearvalues (global_State *g, GCObject *l, GCObject *f) {
- for (; l != f; l = gco2t(l)->gclist) {
- Table *h = gco2t(l);
- Node *n, *limit = gnodelast(h);
- int i;
- for (i = 0; i < h->sizearray; i++) {
- TValue *o = &h->array[i];
- if (iscleared(g, o)) /* value was collected? */
- setnilvalue(o); /* remove value */
- }
- for (n = gnode(h, 0); n < limit; n++) {
- if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {
- setnilvalue(gval(n)); /* remove value ... */
- removeentry(n); /* and remove entry from table */
- }
- }
- }
+ for (; l != f; l = gco2t(l)->gclist) {
+ Table *h = gco2t(l);
+ Node *n, *limit = gnodelast(h);
+ int i;
+ for (i = 0; i < h->sizearray; i++) {
+ TValue *o = &h->array[i];
+ if (iscleared(g, o)) /* value was collected? */
+ setnilvalue(o); /* remove value */
+ }
+ for (n = gnode(h, 0); n < limit; n++) {
+ if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {
+ setnilvalue(gval(n)); /* remove value ... */
+ removeentry(n); /* and remove entry from table */
+ }
+ }
+ }
}
static void freeobj (lua_State *L, GCObject *o) {
- switch (gch(o)->tt) {
- case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
- case LUA_TLCL: {
- luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));
- break;
- }
- case LUA_TCCL: {
- luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));
- break;
- }
- case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
- case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
- case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
- case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
- case LUA_TSHRSTR:
- G(L)->strt.nuse--;
- /* go through */
- case LUA_TLNGSTR: {
- luaM_freemem(L, o, sizestring(gco2ts(o)));
- break;
- }
- default: lua_assert(0);
- }
+ switch (gch(o)->tt) {
+ case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
+ case LUA_TLCL: {
+ luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));
+ break;
+ }
+ case LUA_TCCL: {
+ luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));
+ break;
+ }
+ case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
+ case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
+ case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
+ case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
+ case LUA_TSHRSTR:
+ G(L)->strt.nuse--;
+ /* go through */
+ case LUA_TLNGSTR: {
+ luaM_freemem(L, o, sizestring(gco2ts(o)));
+ break;
+ }
+ default: lua_assert(0);
+ }
}
-#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM)
+#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM)
static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count);
@@ -689,12 +689,12 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count);
** list of call-info structures.
*/
static void sweepthread (lua_State *L, lua_State *L1) {
- if (L1->stack == NULL) return; /* stack not completely built yet */
- sweepwholelist(L, &L1->openupval); /* sweep open upvalues */
- luaE_freeCI(L1); /* free extra CallInfo slots */
- /* should not change the stack during an emergency gc cycle */
- if (G(L)->gckind != KGC_EMERGENCY)
- luaD_shrinkstack(L1);
+ if (L1->stack == NULL) return; /* stack not completely built yet */
+ sweepwholelist(L, &L1->openupval); /* sweep open upvalues */
+ luaE_freeCI(L1); /* free extra CallInfo slots */
+ /* should not change the stack during an emergency gc cycle */
+ if (G(L)->gckind != KGC_EMERGENCY)
+ luaD_shrinkstack(L1);
}
@@ -710,38 +710,38 @@ static void sweepthread (lua_State *L, lua_State *L1) {
** When object is a thread, sweep its list of open upvalues too.
*/
static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
- global_State *g = G(L);
- int ow = otherwhite(g);
- int toclear, toset; /* bits to clear and to set in all live objects */
- int tostop; /* stop sweep when this is true */
- if (isgenerational(g)) { /* generational mode? */
- toclear = ~0; /* clear nothing */
- toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */
- tostop = bitmask(OLDBIT); /* do not sweep old generation */
- }
- else { /* normal mode */
- toclear = maskcolors; /* clear all color bits + old bit */
- toset = luaC_white(g); /* make object white */
- tostop = 0; /* do not stop */
- }
- while (*p != NULL && count-- > 0) {
- GCObject *curr = *p;
- int marked = gch(curr)->marked;
- if (isdeadm(ow, marked)) { /* is 'curr' dead? */
- *p = gch(curr)->next; /* remove 'curr' from list */
- freeobj(L, curr); /* erase 'curr' */
- }
- else {
- if (testbits(marked, tostop))
- return NULL; /* stop sweeping this list */
- if (gch(curr)->tt == LUA_TTHREAD)
- sweepthread(L, gco2th(curr)); /* sweep thread's upvalues */
- /* update marks */
- gch(curr)->marked = cast_byte((marked & toclear) | toset);
- p = &gch(curr)->next; /* go to next element */
- }
- }
- return (*p == NULL) ? NULL : p;
+ global_State *g = G(L);
+ int ow = otherwhite(g);
+ int toclear, toset; /* bits to clear and to set in all live objects */
+ int tostop; /* stop sweep when this is true */
+ if (isgenerational(g)) { /* generational mode? */
+ toclear = ~0; /* clear nothing */
+ toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */
+ tostop = bitmask(OLDBIT); /* do not sweep old generation */
+ }
+ else { /* normal mode */
+ toclear = maskcolors; /* clear all color bits + old bit */
+ toset = luaC_white(g); /* make object white */
+ tostop = 0; /* do not stop */
+ }
+ while (*p != NULL && count-- > 0) {
+ GCObject *curr = *p;
+ int marked = gch(curr)->marked;
+ if (isdeadm(ow, marked)) { /* is 'curr' dead? */
+ *p = gch(curr)->next; /* remove 'curr' from list */
+ freeobj(L, curr); /* erase 'curr' */
+ }
+ else {
+ if (testbits(marked, tostop))
+ return NULL; /* stop sweeping this list */
+ if (gch(curr)->tt == LUA_TTHREAD)
+ sweepthread(L, gco2th(curr)); /* sweep thread's upvalues */
+ /* update marks */
+ gch(curr)->marked = cast_byte((marked & toclear) | toset);
+ p = &gch(curr)->next; /* go to next element */
+ }
+ }
+ return (*p == NULL) ? NULL : p;
}
@@ -749,14 +749,14 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
** sweep a list until a live object (or end of list)
*/
static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) {
- GCObject ** old = p;
- int i = 0;
- do {
- i++;
- p = sweeplist(L, p, 1);
- } while (p == old);
- if (n) *n += i;
- return p;
+ GCObject ** old = p;
+ int i = 0;
+ do {
+ i++;
+ p = sweeplist(L, p, 1);
+ } while (p == old);
+ if (n) *n += i;
+ return p;
}
/* }====================================================== */
@@ -769,65 +769,65 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) {
*/
static void checkSizes (lua_State *L) {
- global_State *g = G(L);
- if (g->gckind != KGC_EMERGENCY) { /* do not change sizes in emergency */
- int hs = g->strt.size / 2; /* half the size of the string table */
- if (g->strt.nuse < cast(lu_int32, hs)) /* using less than that half? */
- luaS_resize(L, hs); /* halve its size */
- luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */
- }
+ global_State *g = G(L);
+ if (g->gckind != KGC_EMERGENCY) { /* do not change sizes in emergency */
+ int hs = g->strt.size / 2; /* half the size of the string table */
+ if (g->strt.nuse < cast(lu_int32, hs)) /* using less than that half? */
+ luaS_resize(L, hs); /* halve its size */
+ luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */
+ }
}
static GCObject *udata2finalize (global_State *g) {
- GCObject *o = g->tobefnz; /* get first element */
- lua_assert(isfinalized(o));
- g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */
- gch(o)->next = g->allgc; /* return it to 'allgc' list */
- g->allgc = o;
- resetbit(gch(o)->marked, SEPARATED); /* mark that it is not in 'tobefnz' */
- lua_assert(!isold(o)); /* see MOVE OLD rule */
- if (!keepinvariantout(g)) /* not keeping invariant? */
- makewhite(g, o); /* "sweep" object */
- return o;
+ GCObject *o = g->tobefnz; /* get first element */
+ lua_assert(isfinalized(o));
+ g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */
+ gch(o)->next = g->allgc; /* return it to 'allgc' list */
+ g->allgc = o;
+ resetbit(gch(o)->marked, SEPARATED); /* mark that it is not in 'tobefnz' */
+ lua_assert(!isold(o)); /* see MOVE OLD rule */
+ if (!keepinvariantout(g)) /* not keeping invariant? */
+ makewhite(g, o); /* "sweep" object */
+ return o;
}
static void dothecall (lua_State *L, void *ud) {
- UNUSED(ud);
- luaD_call(L, L->top - 2, 0, 0);
+ UNUSED(ud);
+ luaD_call(L, L->top - 2, 0, 0);
}
static void GCTM (lua_State *L, int propagateerrors) {
- global_State *g = G(L);
- const TValue *tm;
- TValue v;
- setgcovalue(L, &v, udata2finalize(g));
- tm = luaT_gettmbyobj(L, &v, TM_GC);
- if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */
- int status;
- lu_byte oldah = L->allowhook;
- int running = g->gcrunning;
- L->allowhook = 0; /* stop debug hooks during GC metamethod */
- g->gcrunning = 0; /* avoid GC steps */
- setobj2s(L, L->top, tm); /* push finalizer... */
- setobj2s(L, L->top + 1, &v); /* ... and its argument */
- L->top += 2; /* and (next line) call the finalizer */
- status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
- L->allowhook = oldah; /* restore hooks */
- g->gcrunning = running; /* restore state */
- if (status != LUA_OK && propagateerrors) { /* error while running __gc? */
- if (status == LUA_ERRRUN) { /* is there an error object? */
- const char *msg = (ttisstring(L->top - 1))
- ? svalue(L->top - 1)
- : "no message";
- luaO_pushfstring(L, "error in __gc metamethod (%s)", msg);
- status = LUA_ERRGCMM; /* error in __gc metamethod */
- }
- luaD_throw(L, status); /* re-throw error */
- }
- }
+ global_State *g = G(L);
+ const TValue *tm;
+ TValue v;
+ setgcovalue(L, &v, udata2finalize(g));
+ tm = luaT_gettmbyobj(L, &v, TM_GC);
+ if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */
+ int status;
+ lu_byte oldah = L->allowhook;
+ int running = g->gcrunning;
+ L->allowhook = 0; /* stop debug hooks during GC metamethod */
+ g->gcrunning = 0; /* avoid GC steps */
+ setobj2s(L, L->top, tm); /* push finalizer... */
+ setobj2s(L, L->top + 1, &v); /* ... and its argument */
+ L->top += 2; /* and (next line) call the finalizer */
+ status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
+ L->allowhook = oldah; /* restore hooks */
+ g->gcrunning = running; /* restore state */
+ if (status != LUA_OK && propagateerrors) { /* error while running __gc? */
+ if (status == LUA_ERRRUN) { /* is there an error object? */
+ const char *msg = (ttisstring(L->top - 1))
+ ? svalue(L->top - 1)
+ : "no message";
+ luaO_pushfstring(L, "error in __gc metamethod (%s)", msg);
+ status = LUA_ERRGCMM; /* error in __gc metamethod */
+ }
+ luaD_throw(L, status); /* re-throw error */
+ }
+ }
}
@@ -836,26 +836,26 @@ static void GCTM (lua_State *L, int propagateerrors) {
** finalization from list 'finobj' to list 'tobefnz' (to be finalized)
*/
static void separatetobefnz (lua_State *L, int all) {
- global_State *g = G(L);
- GCObject **p = &g->finobj;
- GCObject *curr;
- GCObject **lastnext = &g->tobefnz;
- /* find last 'next' field in 'tobefnz' list (to add elements in its end) */
- while (*lastnext != NULL)
- lastnext = &gch(*lastnext)->next;
- while ((curr = *p) != NULL) { /* traverse all finalizable objects */
- lua_assert(!isfinalized(curr));
- lua_assert(testbit(gch(curr)->marked, SEPARATED));
- if (!(iswhite(curr) || all)) /* not being collected? */
- p = &gch(curr)->next; /* don't bother with it */
- else {
- l_setbit(gch(curr)->marked, FINALIZEDBIT); /* won't be finalized again */
- *p = gch(curr)->next; /* remove 'curr' from 'finobj' list */
- gch(curr)->next = *lastnext; /* link at the end of 'tobefnz' list */
- *lastnext = curr;
- lastnext = &gch(curr)->next;
- }
- }
+ global_State *g = G(L);
+ GCObject **p = &g->finobj;
+ GCObject *curr;
+ GCObject **lastnext = &g->tobefnz;
+ /* find last 'next' field in 'tobefnz' list (to add elements in its end) */
+ while (*lastnext != NULL)
+ lastnext = &gch(*lastnext)->next;
+ while ((curr = *p) != NULL) { /* traverse all finalizable objects */
+ lua_assert(!isfinalized(curr));
+ lua_assert(testbit(gch(curr)->marked, SEPARATED));
+ if (!(iswhite(curr) || all)) /* not being collected? */
+ p = &gch(curr)->next; /* don't bother with it */
+ else {
+ l_setbit(gch(curr)->marked, FINALIZEDBIT); /* won't be finalized again */
+ *p = gch(curr)->next; /* remove 'curr' from 'finobj' list */
+ gch(curr)->next = *lastnext; /* link at the end of 'tobefnz' list */
+ *lastnext = curr;
+ lastnext = &gch(curr)->next;
+ }
+ }
}
@@ -864,29 +864,29 @@ static void separatetobefnz (lua_State *L, int all) {
** search the list to find it) and link it in 'finobj' list.
*/
void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
- global_State *g = G(L);
- if (testbit(gch(o)->marked, SEPARATED) || /* obj. is already separated... */
- isfinalized(o) || /* ... or is finalized... */
- gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */
- return; /* nothing to be done */
- else { /* move 'o' to 'finobj' list */
- GCObject **p;
- GCheader *ho = gch(o);
- if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */
- lua_assert(issweepphase(g));
- g->sweepgc = sweeptolive(L, g->sweepgc, NULL);
- }
- /* search for pointer pointing to 'o' */
- for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ }
- *p = ho->next; /* remove 'o' from root list */
- ho->next = g->finobj; /* link it in list 'finobj' */
- g->finobj = o;
- l_setbit(ho->marked, SEPARATED); /* mark it as such */
- if (!keepinvariantout(g)) /* not keeping invariant? */
- makewhite(g, o); /* "sweep" object */
- else
- resetoldbit(o); /* see MOVE OLD rule */
- }
+ global_State *g = G(L);
+ if (testbit(gch(o)->marked, SEPARATED) || /* obj. is already separated... */
+ isfinalized(o) || /* ... or is finalized... */
+ gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */
+ return; /* nothing to be done */
+ else { /* move 'o' to 'finobj' list */
+ GCObject **p;
+ GCheader *ho = gch(o);
+ if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */
+ lua_assert(issweepphase(g));
+ g->sweepgc = sweeptolive(L, g->sweepgc, NULL);
+ }
+ /* search for pointer pointing to 'o' */
+ for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ }
+ *p = ho->next; /* remove 'o' from root list */
+ ho->next = g->finobj; /* link it in list 'finobj' */
+ g->finobj = o;
+ l_setbit(ho->marked, SEPARATED); /* mark it as such */
+ if (!keepinvariantout(g)) /* not keeping invariant? */
+ makewhite(g, o); /* "sweep" object */
+ else
+ resetoldbit(o); /* see MOVE OLD rule */
+ }
}
/* }====================================================== */
@@ -904,13 +904,13 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
** cycle will start when memory use hits threshold
*/
static void setpause (global_State *g, l_mem estimate) {
- l_mem debt, threshold;
- estimate = estimate / PAUSEADJ; /* adjust 'estimate' */
- threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
- ? estimate * g->gcpause /* no overflow */
- : MAX_LMEM; /* overflow; truncate to maximum */
- debt = -cast(l_mem, threshold - gettotalbytes(g));
- luaE_setdebt(g, debt);
+ l_mem debt, threshold;
+ estimate = estimate / PAUSEADJ; /* adjust 'estimate' */
+ threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
+ ? estimate * g->gcpause /* no overflow */
+ : MAX_LMEM; /* overflow; truncate to maximum */
+ debt = -cast(l_mem, threshold - gettotalbytes(g));
+ luaE_setdebt(g, debt);
}
@@ -927,15 +927,15 @@ static void setpause (global_State *g, l_mem estimate) {
** Returns how many objects it swept.
*/
static int entersweep (lua_State *L) {
- global_State *g = G(L);
- int n = 0;
- g->gcstate = GCSsweepstring;
- lua_assert(g->sweepgc == NULL && g->sweepfin == NULL);
- /* prepare to sweep strings, finalizable objects, and regular objects */
- g->sweepstrgc = 0;
- g->sweepfin = sweeptolive(L, &g->finobj, &n);
- g->sweepgc = sweeptolive(L, &g->allgc, &n);
- return n;
+ global_State *g = G(L);
+ int n = 0;
+ g->gcstate = GCSsweepstring;
+ lua_assert(g->sweepgc == NULL && g->sweepfin == NULL);
+ /* prepare to sweep strings, finalizable objects, and regular objects */
+ g->sweepstrgc = 0;
+ g->sweepfin = sweeptolive(L, &g->finobj, &n);
+ g->sweepgc = sweeptolive(L, &g->allgc, &n);
+ return n;
}
@@ -943,21 +943,21 @@ static int entersweep (lua_State *L) {
** change GC mode
*/
void luaC_changemode (lua_State *L, int mode) {
- global_State *g = G(L);
- if (mode == g->gckind) return; /* nothing to change */
- if (mode == KGC_GEN) { /* change to generational mode */
- /* make sure gray lists are consistent */
- luaC_runtilstate(L, bitmask(GCSpropagate));
- g->GCestimate = gettotalbytes(g);
- g->gckind = KGC_GEN;
- }
- else { /* change to incremental mode */
- /* sweep all objects to turn them back to white
- (as white has not changed, nothing extra will be collected) */
- g->gckind = KGC_NORMAL;
- entersweep(L);
- luaC_runtilstate(L, ~sweepphases);
- }
+ global_State *g = G(L);
+ if (mode == g->gckind) return; /* nothing to change */
+ if (mode == KGC_GEN) { /* change to generational mode */
+ /* make sure gray lists are consistent */
+ luaC_runtilstate(L, bitmask(GCSpropagate));
+ g->GCestimate = gettotalbytes(g);
+ g->gckind = KGC_GEN;
+ }
+ else { /* change to incremental mode */
+ /* sweep all objects to turn them back to white
+ (as white has not changed, nothing extra will be collected) */
+ g->gckind = KGC_NORMAL;
+ entersweep(L);
+ luaC_runtilstate(L, ~sweepphases);
+ }
}
@@ -965,134 +965,134 @@ void luaC_changemode (lua_State *L, int mode) {
** call all pending finalizers
*/
static void callallpendingfinalizers (lua_State *L, int propagateerrors) {
- global_State *g = G(L);
- while (g->tobefnz) {
- resetoldbit(g->tobefnz);
- GCTM(L, propagateerrors);
- }
+ global_State *g = G(L);
+ while (g->tobefnz) {
+ resetoldbit(g->tobefnz);
+ GCTM(L, propagateerrors);
+ }
}
void luaC_freeallobjects (lua_State *L) {
- global_State *g = G(L);
- int i;
- separatetobefnz(L, 1); /* separate all objects with finalizers */
- lua_assert(g->finobj == NULL);
- callallpendingfinalizers(L, 0);
- g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */
- g->gckind = KGC_NORMAL;
- sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */
- sweepwholelist(L, &g->allgc);
- for (i = 0; i < g->strt.size; i++) /* free all string lists */
- sweepwholelist(L, &g->strt.hash[i]);
- lua_assert(g->strt.nuse == 0);
+ global_State *g = G(L);
+ int i;
+ separatetobefnz(L, 1); /* separate all objects with finalizers */
+ lua_assert(g->finobj == NULL);
+ callallpendingfinalizers(L, 0);
+ g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */
+ g->gckind = KGC_NORMAL;
+ sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */
+ sweepwholelist(L, &g->allgc);
+ for (i = 0; i < g->strt.size; i++) /* free all string lists */
+ sweepwholelist(L, &g->strt.hash[i]);
+ lua_assert(g->strt.nuse == 0);
}
static l_mem atomic (lua_State *L) {
- global_State *g = G(L);
- l_mem work = -cast(l_mem, g->GCmemtrav); /* start counting work */
- GCObject *origweak, *origall;
- lua_assert(!iswhite(obj2gco(g->mainthread)));
- markobject(g, L); /* mark running thread */
- /* registry and global metatables may be changed by API */
- markvalue(g, &g->l_registry);
- markmt(g); /* mark basic metatables */
- /* remark occasional upvalues of (maybe) dead threads */
- remarkupvals(g);
- propagateall(g); /* propagate changes */
- work += g->GCmemtrav; /* stop counting (do not (re)count grays) */
- /* traverse objects caught by write barrier and by 'remarkupvals' */
- retraversegrays(g);
- work -= g->GCmemtrav; /* restart counting */
- convergeephemerons(g);
- /* at this point, all strongly accessible objects are marked. */
- /* clear values from weak tables, before checking finalizers */
- clearvalues(g, g->weak, NULL);
- clearvalues(g, g->allweak, NULL);
- origweak = g->weak; origall = g->allweak;
- work += g->GCmemtrav; /* stop counting (objects being finalized) */
- separatetobefnz(L, 0); /* separate objects to be finalized */
- markbeingfnz(g); /* mark objects that will be finalized */
- propagateall(g); /* remark, to propagate `preserveness' */
- work -= g->GCmemtrav; /* restart counting */
- convergeephemerons(g);
- /* at this point, all resurrected objects are marked. */
- /* remove dead objects from weak tables */
- clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */
- clearkeys(g, g->allweak, NULL); /* clear keys from all allweak tables */
- /* clear values from resurrected weak tables */
- clearvalues(g, g->weak, origweak);
- clearvalues(g, g->allweak, origall);
- g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
- work += g->GCmemtrav; /* complete counting */
- return work; /* estimate of memory marked by 'atomic' */
+ global_State *g = G(L);
+ l_mem work = -cast(l_mem, g->GCmemtrav); /* start counting work */
+ GCObject *origweak, *origall;
+ lua_assert(!iswhite(obj2gco(g->mainthread)));
+ markobject(g, L); /* mark running thread */
+ /* registry and global metatables may be changed by API */
+ markvalue(g, &g->l_registry);
+ markmt(g); /* mark basic metatables */
+ /* remark occasional upvalues of (maybe) dead threads */
+ remarkupvals(g);
+ propagateall(g); /* propagate changes */
+ work += g->GCmemtrav; /* stop counting (do not (re)count grays) */
+ /* traverse objects caught by write barrier and by 'remarkupvals' */
+ retraversegrays(g);
+ work -= g->GCmemtrav; /* restart counting */
+ convergeephemerons(g);
+ /* at this point, all strongly accessible objects are marked. */
+ /* clear values from weak tables, before checking finalizers */
+ clearvalues(g, g->weak, NULL);
+ clearvalues(g, g->allweak, NULL);
+ origweak = g->weak; origall = g->allweak;
+ work += g->GCmemtrav; /* stop counting (objects being finalized) */
+ separatetobefnz(L, 0); /* separate objects to be finalized */
+ markbeingfnz(g); /* mark objects that will be finalized */
+ propagateall(g); /* remark, to propagate `preserveness' */
+ work -= g->GCmemtrav; /* restart counting */
+ convergeephemerons(g);
+ /* at this point, all resurrected objects are marked. */
+ /* remove dead objects from weak tables */
+ clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */
+ clearkeys(g, g->allweak, NULL); /* clear keys from all allweak tables */
+ /* clear values from resurrected weak tables */
+ clearvalues(g, g->weak, origweak);
+ clearvalues(g, g->allweak, origall);
+ g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
+ work += g->GCmemtrav; /* complete counting */
+ return work; /* estimate of memory marked by 'atomic' */
}
static lu_mem singlestep (lua_State *L) {
- global_State *g = G(L);
- switch (g->gcstate) {
- case GCSpause: {
- /* start to count memory traversed */
- g->GCmemtrav = g->strt.size * sizeof(GCObject*);
- lua_assert(!isgenerational(g));
- restartcollection(g);
- g->gcstate = GCSpropagate;
- return g->GCmemtrav;
- }
- case GCSpropagate: {
- if (g->gray) {
- lu_mem oldtrav = g->GCmemtrav;
- propagatemark(g);
- return g->GCmemtrav - oldtrav; /* memory traversed in this step */
- }
- else { /* no more `gray' objects */
- lu_mem work;
- int sw;
- g->gcstate = GCSatomic; /* finish mark phase */
- g->GCestimate = g->GCmemtrav; /* save what was counted */;
- work = atomic(L); /* add what was traversed by 'atomic' */
- g->GCestimate += work; /* estimate of total memory traversed */
- sw = entersweep(L);
- return work + sw * GCSWEEPCOST;
- }
- }
- case GCSsweepstring: {
- int i;
- for (i = 0; i < GCSWEEPMAX && g->sweepstrgc + i < g->strt.size; i++)
- sweepwholelist(L, &g->strt.hash[g->sweepstrgc + i]);
- g->sweepstrgc += i;
- if (g->sweepstrgc >= g->strt.size) /* no more strings to sweep? */
- g->gcstate = GCSsweepudata;
- return i * GCSWEEPCOST;
- }
- case GCSsweepudata: {
- if (g->sweepfin) {
- g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX);
- return GCSWEEPMAX*GCSWEEPCOST;
- }
- else {
- g->gcstate = GCSsweep;
- return 0;
- }
- }
- case GCSsweep: {
- if (g->sweepgc) {
- g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
- return GCSWEEPMAX*GCSWEEPCOST;
- }
- else {
- /* sweep main thread */
- GCObject *mt = obj2gco(g->mainthread);
- sweeplist(L, &mt, 1);
- checkSizes(L);
- g->gcstate = GCSpause; /* finish collection */
- return GCSWEEPCOST;
- }
- }
- default: lua_assert(0); return 0;
- }
+ global_State *g = G(L);
+ switch (g->gcstate) {
+ case GCSpause: {
+ /* start to count memory traversed */
+ g->GCmemtrav = g->strt.size * sizeof(GCObject*);
+ lua_assert(!isgenerational(g));
+ restartcollection(g);
+ g->gcstate = GCSpropagate;
+ return g->GCmemtrav;
+ }
+ case GCSpropagate: {
+ if (g->gray) {
+ lu_mem oldtrav = g->GCmemtrav;
+ propagatemark(g);
+ return g->GCmemtrav - oldtrav; /* memory traversed in this step */
+ }
+ else { /* no more `gray' objects */
+ lu_mem work;
+ int sw;
+ g->gcstate = GCSatomic; /* finish mark phase */
+ g->GCestimate = g->GCmemtrav; /* save what was counted */;
+ work = atomic(L); /* add what was traversed by 'atomic' */
+ g->GCestimate += work; /* estimate of total memory traversed */
+ sw = entersweep(L);
+ return work + sw * GCSWEEPCOST;
+ }
+ }
+ case GCSsweepstring: {
+ int i;
+ for (i = 0; i < GCSWEEPMAX && g->sweepstrgc + i < g->strt.size; i++)
+ sweepwholelist(L, &g->strt.hash[g->sweepstrgc + i]);
+ g->sweepstrgc += i;
+ if (g->sweepstrgc >= g->strt.size) /* no more strings to sweep? */
+ g->gcstate = GCSsweepudata;
+ return i * GCSWEEPCOST;
+ }
+ case GCSsweepudata: {
+ if (g->sweepfin) {
+ g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX);
+ return GCSWEEPMAX*GCSWEEPCOST;
+ }
+ else {
+ g->gcstate = GCSsweep;
+ return 0;
+ }
+ }
+ case GCSsweep: {
+ if (g->sweepgc) {
+ g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
+ return GCSWEEPMAX*GCSWEEPCOST;
+ }
+ else {
+ /* sweep main thread */
+ GCObject *mt = obj2gco(g->mainthread);
+ sweeplist(L, &mt, 1);
+ checkSizes(L);
+ g->gcstate = GCSpause; /* finish collection */
+ return GCSWEEPCOST;
+ }
+ }
+ default: lua_assert(0); return 0;
+ }
}
@@ -1101,52 +1101,52 @@ static lu_mem singlestep (lua_State *L) {
** by 'statemask'
*/
void luaC_runtilstate (lua_State *L, int statesmask) {
- global_State *g = G(L);
- while (!testbit(statesmask, g->gcstate))
- singlestep(L);
+ global_State *g = G(L);
+ while (!testbit(statesmask, g->gcstate))
+ singlestep(L);
}
static void generationalcollection (lua_State *L) {
- global_State *g = G(L);
- lua_assert(g->gcstate == GCSpropagate);
- if (g->GCestimate == 0) { /* signal for another major collection? */
- luaC_fullgc(L, 0); /* perform a full regular collection */
- g->GCestimate = gettotalbytes(g); /* update control */
- }
- else {
- lu_mem estimate = g->GCestimate;
- luaC_runtilstate(L, bitmask(GCSpause)); /* run complete (minor) cycle */
- g->gcstate = GCSpropagate; /* skip restart */
- if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc)
- g->GCestimate = 0; /* signal for a major collection */
- else
- g->GCestimate = estimate; /* keep estimate from last major coll. */
-
- }
- setpause(g, gettotalbytes(g));
- lua_assert(g->gcstate == GCSpropagate);
+ global_State *g = G(L);
+ lua_assert(g->gcstate == GCSpropagate);
+ if (g->GCestimate == 0) { /* signal for another major collection? */
+ luaC_fullgc(L, 0); /* perform a full regular collection */
+ g->GCestimate = gettotalbytes(g); /* update control */
+ }
+ else {
+ lu_mem estimate = g->GCestimate;
+ luaC_runtilstate(L, bitmask(GCSpause)); /* run complete (minor) cycle */
+ g->gcstate = GCSpropagate; /* skip restart */
+ if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc)
+ g->GCestimate = 0; /* signal for a major collection */
+ else
+ g->GCestimate = estimate; /* keep estimate from last major coll. */
+
+ }
+ setpause(g, gettotalbytes(g));
+ lua_assert(g->gcstate == GCSpropagate);
}
static void incstep (lua_State *L) {
- global_State *g = G(L);
- l_mem debt = g->GCdebt;
- int stepmul = g->gcstepmul;
- if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values (and 0) */
- /* convert debt from Kb to 'work units' (avoid zero debt and overflows) */
- debt = (debt / STEPMULADJ) + 1;
- debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
- do { /* always perform at least one single step */
- lu_mem work = singlestep(L); /* do some work */
- debt -= work;
- } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
- if (g->gcstate == GCSpause)
- setpause(g, g->GCestimate); /* pause until next cycle */
- else {
- debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */
- luaE_setdebt(g, debt);
- }
+ global_State *g = G(L);
+ l_mem debt = g->GCdebt;
+ int stepmul = g->gcstepmul;
+ if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values (and 0) */
+ /* convert debt from Kb to 'work units' (avoid zero debt and overflows) */
+ debt = (debt / STEPMULADJ) + 1;
+ debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
+ do { /* always perform at least one single step */
+ lu_mem work = singlestep(L); /* do some work */
+ debt -= work;
+ } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
+ if (g->gcstate == GCSpause)
+ setpause(g, g->GCestimate); /* pause until next cycle */
+ else {
+ debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */
+ luaE_setdebt(g, debt);
+ }
}
@@ -1154,13 +1154,13 @@ static void incstep (lua_State *L) {
** performs a basic GC step
*/
void luaC_forcestep (lua_State *L) {
- global_State *g = G(L);
- int i;
- if (isgenerational(g)) generationalcollection(L);
- else incstep(L);
- /* run a few finalizers (or all of them at the end of a collect cycle) */
- for (i = 0; g->tobefnz && (i < GCFINALIZENUM || g->gcstate == GCSpause); i++)
- GCTM(L, 1); /* call one finalizer */
+ global_State *g = G(L);
+ int i;
+ if (isgenerational(g)) generationalcollection(L);
+ else incstep(L);
+ /* run a few finalizers (or all of them at the end of a collect cycle) */
+ for (i = 0; g->tobefnz && (i < GCFINALIZENUM || g->gcstate == GCSpause); i++)
+ GCTM(L, 1); /* call one finalizer */
}
@@ -1168,9 +1168,9 @@ void luaC_forcestep (lua_State *L) {
** performs a basic GC step only if collector is running
*/
void luaC_step (lua_State *L) {
- global_State *g = G(L);
- if (g->gcrunning) luaC_forcestep(L);
- else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */
+ global_State *g = G(L);
+ if (g->gcrunning) luaC_forcestep(L);
+ else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */
}
@@ -1180,34 +1180,32 @@ void luaC_step (lua_State *L) {
** finalizers (which could change stack positions)
*/
void luaC_fullgc (lua_State *L, int isemergency) {
- global_State *g = G(L);
- int origkind = g->gckind;
- lua_assert(origkind != KGC_EMERGENCY);
- if (isemergency) /* do not run finalizers during emergency GC */
- g->gckind = KGC_EMERGENCY;
- else {
- g->gckind = KGC_NORMAL;
- callallpendingfinalizers(L, 1);
- }
- if (keepinvariant(g)) { /* may there be some black objects? */
- /* must sweep all objects to turn them back to white
- (as white has not changed, nothing will be collected) */
- entersweep(L);
- }
- /* finish any pending sweep phase to start a new cycle */
- luaC_runtilstate(L, bitmask(GCSpause));
- luaC_runtilstate(L, ~bitmask(GCSpause)); /* start new collection */
- luaC_runtilstate(L, bitmask(GCSpause)); /* run entire collection */
- if (origkind == KGC_GEN) { /* generational mode? */
- /* generational mode must be kept in propagate phase */
- luaC_runtilstate(L, bitmask(GCSpropagate));
- }
- g->gckind = origkind;
- setpause(g, gettotalbytes(g));
- if (!isemergency) /* do not run finalizers during emergency GC */
- callallpendingfinalizers(L, 1);
+ global_State *g = G(L);
+ int origkind = g->gckind;
+ lua_assert(origkind != KGC_EMERGENCY);
+ if (isemergency) /* do not run finalizers during emergency GC */
+ g->gckind = KGC_EMERGENCY;
+ else {
+ g->gckind = KGC_NORMAL;
+ callallpendingfinalizers(L, 1);
+ }
+ if (keepinvariant(g)) { /* may there be some black objects? */
+ /* must sweep all objects to turn them back to white
+ (as white has not changed, nothing will be collected) */
+ entersweep(L);
+ }
+ /* finish any pending sweep phase to start a new cycle */
+ luaC_runtilstate(L, bitmask(GCSpause));
+ luaC_runtilstate(L, ~bitmask(GCSpause)); /* start new collection */
+ luaC_runtilstate(L, bitmask(GCSpause)); /* run entire collection */
+ if (origkind == KGC_GEN) { /* generational mode? */
+ /* generational mode must be kept in propagate phase */
+ luaC_runtilstate(L, bitmask(GCSpropagate));
+ }
+ g->gckind = origkind;
+ setpause(g, gettotalbytes(g));
+ if (!isemergency) /* do not run finalizers during emergency GC */
+ callallpendingfinalizers(L, 1);
}
/* }====================================================== */
-
-
diff --git a/src/lib/lua/lgc.h b/src/lib/lua/lgc.h
index dee270b4dcb..3cc8f19065f 100644
--- a/src/lib/lua/lgc.h
+++ b/src/lib/lua/lgc.h
@@ -29,25 +29,25 @@
/* how much to allocate before next GC step */
#if !defined(GCSTEPSIZE)
/* ~100 small strings */
-#define GCSTEPSIZE (cast_int(100 * sizeof(TString)))
+#define GCSTEPSIZE (cast_int(100 * sizeof(TString)))
#endif
/*
** Possible states of the Garbage Collector
*/
-#define GCSpropagate 0
-#define GCSatomic 1
-#define GCSsweepstring 2
-#define GCSsweepudata 3
-#define GCSsweep 4
-#define GCSpause 5
+#define GCSpropagate 0
+#define GCSatomic 1
+#define GCSsweepstring 2
+#define GCSsweepudata 3
+#define GCSsweep 4
+#define GCSpause 5
#define issweepphase(g) \
(GCSsweepstring <= (g)->gcstate && (g)->gcstate <= GCSsweep)
-#define isgenerational(g) ((g)->gckind == KGC_GEN)
+#define isgenerational(g) ((g)->gckind == KGC_GEN)
/*
** macros to tell when main invariant (white objects cannot point to black
@@ -58,7 +58,7 @@
** invariant must be kept all times.
*/
-#define keepinvariant(g) (isgenerational(g) || g->gcstate <= GCSatomic)
+#define keepinvariant(g) (isgenerational(g) || g->gcstate <= GCSatomic)
/*
@@ -66,34 +66,34 @@
** 'propagate', so 'keepinvariant' is always true.
*/
#define keepinvariantout(g) \
- check_exp(g->gcstate == GCSpropagate || !isgenerational(g), \
- g->gcstate <= GCSatomic)
+ check_exp(g->gcstate == GCSpropagate || !isgenerational(g), \
+ g->gcstate <= GCSatomic)
/*
** some useful bit tricks
*/
-#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
-#define setbits(x,m) ((x) |= (m))
-#define testbits(x,m) ((x) & (m))
-#define bitmask(b) (1<<(b))
-#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
-#define l_setbit(x,b) setbits(x, bitmask(b))
-#define resetbit(x,b) resetbits(x, bitmask(b))
-#define testbit(x,b) testbits(x, bitmask(b))
+#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
+#define setbits(x,m) ((x) |= (m))
+#define testbits(x,m) ((x) & (m))
+#define bitmask(b) (1<<(b))
+#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
+#define l_setbit(x,b) setbits(x, bitmask(b))
+#define resetbit(x,b) resetbits(x, bitmask(b))
+#define testbit(x,b) testbits(x, bitmask(b))
/* Layout for bit use in `marked' field: */
-#define WHITE0BIT 0 /* object is white (type 0) */
-#define WHITE1BIT 1 /* object is white (type 1) */
-#define BLACKBIT 2 /* object is black */
-#define FINALIZEDBIT 3 /* object has been separated for finalization */
-#define SEPARATED 4 /* object is in 'finobj' list or in 'tobefnz' */
-#define FIXEDBIT 5 /* object is fixed (should not be collected) */
-#define OLDBIT 6 /* object is old (only in generational mode) */
+#define WHITE0BIT 0 /* object is white (type 0) */
+#define WHITE1BIT 1 /* object is white (type 1) */
+#define BLACKBIT 2 /* object is black */
+#define FINALIZEDBIT 3 /* object has been separated for finalization */
+#define SEPARATED 4 /* object is in 'finobj' list or in 'tobefnz' */
+#define FIXEDBIT 5 /* object is fixed (should not be collected) */
+#define OLDBIT 6 /* object is old (only in generational mode) */
/* bit 7 is currently used by tests (luaL_checkmemory) */
-#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
+#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
#define iswhite(x) testbits((x)->gch.marked, WHITEBITS)
@@ -101,27 +101,27 @@
#define isgray(x) /* neither white nor black */ \
(!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT)))
-#define isold(x) testbit((x)->gch.marked, OLDBIT)
+#define isold(x) testbit((x)->gch.marked, OLDBIT)
/* MOVE OLD rule: whenever an object is moved to the beginning of
a GC list, its old bit must be cleared */
-#define resetoldbit(o) resetbit((o)->gch.marked, OLDBIT)
+#define resetoldbit(o) resetbit((o)->gch.marked, OLDBIT)
-#define otherwhite(g) (g->currentwhite ^ WHITEBITS)
-#define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow)))
-#define isdead(g,v) isdeadm(otherwhite(g), (v)->gch.marked)
+#define otherwhite(g) (g->currentwhite ^ WHITEBITS)
+#define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow)))
+#define isdead(g,v) isdeadm(otherwhite(g), (v)->gch.marked)
-#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
-#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
+#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
+#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
-#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
+#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
-#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
+#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
#define luaC_condGC(L,c) \
{if (G(L)->GCdebt > 0) {c;}; condchangemem(L);}
-#define luaC_checkGC(L) luaC_condGC(L, luaC_step(L);)
+#define luaC_checkGC(L) luaC_condGC(L, luaC_step(L);)
#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
@@ -135,10 +135,10 @@
luaC_barrier_(L,obj2gco(p),obj2gco(o)); }
#define luaC_objbarrierback(L,p,o) \
- { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) luaC_barrierback_(L,p); }
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) luaC_barrierback_(L,p); }
#define luaC_barrierproto(L,p,c) \
- { if (isblack(obj2gco(p))) luaC_barrierproto_(L,p,c); }
+ { if (isblack(obj2gco(p))) luaC_barrierproto_(L,p,c); }
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
LUAI_FUNC void luaC_step (lua_State *L);
@@ -146,7 +146,7 @@ LUAI_FUNC void luaC_forcestep (lua_State *L);
LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz,
- GCObject **list, int offset);
+ GCObject **list, int offset);
LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);
LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o);
LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c);
diff --git a/src/lib/lua/linit.c b/src/lib/lua/linit.c
index 8d3aa6576fc..cf9bbd1e403 100644
--- a/src/lib/lua/linit.c
+++ b/src/lib/lua/linit.c
@@ -27,17 +27,17 @@
** program
*/
static const luaL_Reg loadedlibs[] = {
- {"_G", luaopen_base},
- {LUA_LOADLIBNAME, luaopen_package},
- {LUA_COLIBNAME, luaopen_coroutine},
- {LUA_TABLIBNAME, luaopen_table},
- {LUA_IOLIBNAME, luaopen_io},
- {LUA_OSLIBNAME, luaopen_os},
- {LUA_STRLIBNAME, luaopen_string},
- {LUA_BITLIBNAME, luaopen_bit32},
- {LUA_MATHLIBNAME, luaopen_math},
- {LUA_DBLIBNAME, luaopen_debug},
- {NULL, NULL}
+ {"_G", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_COLIBNAME, luaopen_coroutine},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_IOLIBNAME, luaopen_io},
+ {LUA_OSLIBNAME, luaopen_os},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_BITLIBNAME, luaopen_bit32},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_DBLIBNAME, luaopen_debug},
+ {NULL, NULL}
};
@@ -45,23 +45,22 @@ static const luaL_Reg loadedlibs[] = {
** these libs are preloaded and must be required before used
*/
static const luaL_Reg preloadedlibs[] = {
- {NULL, NULL}
+ {NULL, NULL}
};
LUALIB_API void luaL_openlibs (lua_State *L) {
- const luaL_Reg *lib;
- /* call open functions from 'loadedlibs' and set results to global table */
- for (lib = loadedlibs; lib->func; lib++) {
- luaL_requiref(L, lib->name, lib->func, 1);
- lua_pop(L, 1); /* remove lib */
- }
- /* add open functions from 'preloadedlibs' into 'package.preload' table */
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
- for (lib = preloadedlibs; lib->func; lib++) {
- lua_pushcfunction(L, lib->func);
- lua_setfield(L, -2, lib->name);
- }
- lua_pop(L, 1); /* remove _PRELOAD table */
+ const luaL_Reg *lib;
+ /* call open functions from 'loadedlibs' and set results to global table */
+ for (lib = loadedlibs; lib->func; lib++) {
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1); /* remove lib */
+ }
+ /* add open functions from 'preloadedlibs' into 'package.preload' table */
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
+ for (lib = preloadedlibs; lib->func; lib++) {
+ lua_pushcfunction(L, lib->func);
+ lua_setfield(L, -2, lib->name);
+ }
+ lua_pop(L, 1); /* remove _PRELOAD table */
}
-
diff --git a/src/lib/lua/liolib.c b/src/lib/lua/liolib.c
index 914e97071ac..a0c4fce3da1 100644
--- a/src/lib/lua/liolib.c
+++ b/src/lib/lua/liolib.c
@@ -37,9 +37,9 @@
** the standard ones.
*/
#define lua_checkmode(mode) \
- (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
- (*mode != '+' || ++mode) && /* skip if char is '+' */ \
- (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
+ (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
+ (*mode != '+' || ++mode) && /* skip if char is '+' */ \
+ (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
(*mode == '\0'))
#endif
@@ -51,29 +51,29 @@
** =======================================================
*/
-#if !defined(lua_popen) /* { */
+#if !defined(lua_popen) /* { */
-#if defined(LUA_USE_POPEN) /* { */
+#if defined(LUA_USE_POPEN) /* { */
-#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
-#define lua_pclose(L,file) ((void)L, pclose(file))
+#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
+#define lua_pclose(L,file) ((void)L, pclose(file))
-#elif defined(LUA_WIN) /* }{ */
+#elif defined(LUA_WIN) /* }{ */
-#define lua_popen(L,c,m) ((void)L, _popen(c,m))
-#define lua_pclose(L,file) ((void)L, _pclose(file))
+#define lua_popen(L,c,m) ((void)L, _popen(c,m))
+#define lua_pclose(L,file) ((void)L, _pclose(file))
-#else /* }{ */
+#else /* }{ */
-#define lua_popen(L,c,m) ((void)((void)c, m), \
+#define lua_popen(L,c,m) ((void)((void)c, m), \
luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
-#define lua_pclose(L,file) ((void)((void)L, file), -1)
+#define lua_pclose(L,file) ((void)((void)L, file), -1)
-#endif /* } */
+#endif /* } */
-#endif /* } */
+#endif /* } */
/* }====================================================== */
@@ -84,78 +84,78 @@
** =======================================================
*/
-#if !defined(lua_fseek) /* { */
+#if !defined(lua_fseek) /* { */
#if defined(LUA_USE_POSIX)
-#define l_fseek(f,o,w) fseeko(f,o,w)
-#define l_ftell(f) ftello(f)
-#define l_seeknum off_t
+#define l_fseek(f,o,w) fseeko(f,o,w)
+#define l_ftell(f) ftello(f)
+#define l_seeknum off_t
#elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
- && defined(_MSC_VER) && (_MSC_VER >= 1400)
+ && defined(_MSC_VER) && (_MSC_VER >= 1400)
/* Windows (but not DDK) and Visual C++ 2005 or higher */
-#define l_fseek(f,o,w) _fseeki64(f,o,w)
-#define l_ftell(f) _ftelli64(f)
-#define l_seeknum __int64
+#define l_fseek(f,o,w) _fseeki64(f,o,w)
+#define l_ftell(f) _ftelli64(f)
+#define l_seeknum __int64
#else
-#define l_fseek(f,o,w) fseek(f,o,w)
-#define l_ftell(f) ftell(f)
-#define l_seeknum long
+#define l_fseek(f,o,w) fseek(f,o,w)
+#define l_ftell(f) ftell(f)
+#define l_seeknum long
#endif
-#endif /* } */
+#endif /* } */
/* }====================================================== */
-#define IO_PREFIX "_IO_"
-#define IO_INPUT (IO_PREFIX "input")
-#define IO_OUTPUT (IO_PREFIX "output")
+#define IO_PREFIX "_IO_"
+#define IO_INPUT (IO_PREFIX "input")
+#define IO_OUTPUT (IO_PREFIX "output")
typedef luaL_Stream LStream;
-#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
+#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
-#define isclosed(p) ((p)->closef == NULL)
+#define isclosed(p) ((p)->closef == NULL)
static int io_type (lua_State *L) {
- LStream *p;
- luaL_checkany(L, 1);
- p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
- if (p == NULL)
- lua_pushnil(L); /* not a file */
- else if (isclosed(p))
- lua_pushliteral(L, "closed file");
- else
- lua_pushliteral(L, "file");
- return 1;
+ LStream *p;
+ luaL_checkany(L, 1);
+ p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
+ if (p == NULL)
+ lua_pushnil(L); /* not a file */
+ else if (isclosed(p))
+ lua_pushliteral(L, "closed file");
+ else
+ lua_pushliteral(L, "file");
+ return 1;
}
static int f_tostring (lua_State *L) {
- LStream *p = tolstream(L);
- if (isclosed(p))
- lua_pushliteral(L, "file (closed)");
- else
- lua_pushfstring(L, "file (%p)", p->f);
- return 1;
+ LStream *p = tolstream(L);
+ if (isclosed(p))
+ lua_pushliteral(L, "file (closed)");
+ else
+ lua_pushfstring(L, "file (%p)", p->f);
+ return 1;
}
static FILE *tofile (lua_State *L) {
- LStream *p = tolstream(L);
- if (isclosed(p))
- luaL_error(L, "attempt to use a closed file");
- lua_assert(p->f);
- return p->f;
+ LStream *p = tolstream(L);
+ if (isclosed(p))
+ luaL_error(L, "attempt to use a closed file");
+ lua_assert(p->f);
+ return p->f;
}
@@ -165,34 +165,34 @@ static FILE *tofile (lua_State *L) {
** file is not left opened.
*/
static LStream *newprefile (lua_State *L) {
- LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
- p->closef = NULL; /* mark file handle as 'closed' */
- luaL_setmetatable(L, LUA_FILEHANDLE);
- return p;
+ LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
+ p->closef = NULL; /* mark file handle as 'closed' */
+ luaL_setmetatable(L, LUA_FILEHANDLE);
+ return p;
}
static int aux_close (lua_State *L) {
- LStream *p = tolstream(L);
- lua_CFunction cf = p->closef;
- p->closef = NULL; /* mark stream as closed */
- return (*cf)(L); /* close it */
+ LStream *p = tolstream(L);
+ lua_CFunction cf = p->closef;
+ p->closef = NULL; /* mark stream as closed */
+ return (*cf)(L); /* close it */
}
static int io_close (lua_State *L) {
- if (lua_isnone(L, 1)) /* no argument? */
- lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
- tofile(L); /* make sure argument is an open stream */
- return aux_close(L);
+ if (lua_isnone(L, 1)) /* no argument? */
+ lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
+ tofile(L); /* make sure argument is an open stream */
+ return aux_close(L);
}
static int f_gc (lua_State *L) {
- LStream *p = tolstream(L);
- if (!isclosed(p) && p->f != NULL)
- aux_close(L); /* ignore closed and incompletely open files */
- return 0;
+ LStream *p = tolstream(L);
+ if (!isclosed(p) && p->f != NULL)
+ aux_close(L); /* ignore closed and incompletely open files */
+ return 0;
}
@@ -200,36 +200,36 @@ static int f_gc (lua_State *L) {
** function to close regular files
*/
static int io_fclose (lua_State *L) {
- LStream *p = tolstream(L);
- int res = fclose(p->f);
- return luaL_fileresult(L, (res == 0), NULL);
+ LStream *p = tolstream(L);
+ int res = fclose(p->f);
+ return luaL_fileresult(L, (res == 0), NULL);
}
static LStream *newfile (lua_State *L) {
- LStream *p = newprefile(L);
- p->f = NULL;
- p->closef = &io_fclose;
- return p;
+ LStream *p = newprefile(L);
+ p->f = NULL;
+ p->closef = &io_fclose;
+ return p;
}
static void opencheck (lua_State *L, const char *fname, const char *mode) {
- LStream *p = newfile(L);
- p->f = fopen(fname, mode);
- if (p->f == NULL)
- luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
+ LStream *p = newfile(L);
+ p->f = fopen(fname, mode);
+ if (p->f == NULL)
+ luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
}
static int io_open (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
- LStream *p = newfile(L);
- const char *md = mode; /* to traverse/check mode */
- luaL_argcheck(L, lua_checkmode(md), 2, "invalid mode");
- p->f = fopen(filename, mode);
- return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
+ const char *filename = luaL_checkstring(L, 1);
+ const char *mode = luaL_optstring(L, 2, "r");
+ LStream *p = newfile(L);
+ const char *md = mode; /* to traverse/check mode */
+ luaL_argcheck(L, lua_checkmode(md), 2, "invalid mode");
+ p->f = fopen(filename, mode);
+ return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
}
@@ -237,62 +237,62 @@ static int io_open (lua_State *L) {
** function to close 'popen' files
*/
static int io_pclose (lua_State *L) {
- LStream *p = tolstream(L);
- return luaL_execresult(L, lua_pclose(L, p->f));
+ LStream *p = tolstream(L);
+ return luaL_execresult(L, lua_pclose(L, p->f));
}
static int io_popen (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
- LStream *p = newprefile(L);
- p->f = lua_popen(L, filename, mode);
- p->closef = &io_pclose;
- return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
+ const char *filename = luaL_checkstring(L, 1);
+ const char *mode = luaL_optstring(L, 2, "r");
+ LStream *p = newprefile(L);
+ p->f = lua_popen(L, filename, mode);
+ p->closef = &io_pclose;
+ return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
}
static int io_tmpfile (lua_State *L) {
- LStream *p = newfile(L);
- p->f = tmpfile();
- return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
+ LStream *p = newfile(L);
+ p->f = tmpfile();
+ return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
}
static FILE *getiofile (lua_State *L, const char *findex) {
- LStream *p;
- lua_getfield(L, LUA_REGISTRYINDEX, findex);
- p = (LStream *)lua_touserdata(L, -1);
- if (isclosed(p))
- luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
- return p->f;
+ LStream *p;
+ lua_getfield(L, LUA_REGISTRYINDEX, findex);
+ p = (LStream *)lua_touserdata(L, -1);
+ if (isclosed(p))
+ luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
+ return p->f;
}
static int g_iofile (lua_State *L, const char *f, const char *mode) {
- if (!lua_isnoneornil(L, 1)) {
- const char *filename = lua_tostring(L, 1);
- if (filename)
- opencheck(L, filename, mode);
- else {
- tofile(L); /* check that it's a valid file handle */
- lua_pushvalue(L, 1);
- }
- lua_setfield(L, LUA_REGISTRYINDEX, f);
- }
- /* return current value */
- lua_getfield(L, LUA_REGISTRYINDEX, f);
- return 1;
+ if (!lua_isnoneornil(L, 1)) {
+ const char *filename = lua_tostring(L, 1);
+ if (filename)
+ opencheck(L, filename, mode);
+ else {
+ tofile(L); /* check that it's a valid file handle */
+ lua_pushvalue(L, 1);
+ }
+ lua_setfield(L, LUA_REGISTRYINDEX, f);
+ }
+ /* return current value */
+ lua_getfield(L, LUA_REGISTRYINDEX, f);
+ return 1;
}
static int io_input (lua_State *L) {
- return g_iofile(L, IO_INPUT, "r");
+ return g_iofile(L, IO_INPUT, "r");
}
static int io_output (lua_State *L) {
- return g_iofile(L, IO_OUTPUT, "w");
+ return g_iofile(L, IO_OUTPUT, "w");
}
@@ -300,42 +300,42 @@ static int io_readline (lua_State *L);
static void aux_lines (lua_State *L, int toclose) {
- int i;
- int n = lua_gettop(L) - 1; /* number of arguments to read */
- /* ensure that arguments will fit here and into 'io_readline' stack */
- luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
- lua_pushvalue(L, 1); /* file handle */
- lua_pushinteger(L, n); /* number of arguments to read */
- lua_pushboolean(L, toclose); /* close/not close file when finished */
- for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1); /* copy arguments */
- lua_pushcclosure(L, io_readline, 3 + n);
+ int i;
+ int n = lua_gettop(L) - 1; /* number of arguments to read */
+ /* ensure that arguments will fit here and into 'io_readline' stack */
+ luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
+ lua_pushvalue(L, 1); /* file handle */
+ lua_pushinteger(L, n); /* number of arguments to read */
+ lua_pushboolean(L, toclose); /* close/not close file when finished */
+ for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1); /* copy arguments */
+ lua_pushcclosure(L, io_readline, 3 + n);
}
static int f_lines (lua_State *L) {
- tofile(L); /* check that it's a valid file handle */
- aux_lines(L, 0);
- return 1;
+ tofile(L); /* check that it's a valid file handle */
+ aux_lines(L, 0);
+ return 1;
}
static int io_lines (lua_State *L) {
- int toclose;
- if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
- if (lua_isnil(L, 1)) { /* no file name? */
- lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
- lua_replace(L, 1); /* put it at index 1 */
- tofile(L); /* check that it's a valid file handle */
- toclose = 0; /* do not close it after iteration */
- }
- else { /* open a new file */
- const char *filename = luaL_checkstring(L, 1);
- opencheck(L, filename, "r");
- lua_replace(L, 1); /* put file at index 1 */
- toclose = 1; /* close it after iteration */
- }
- aux_lines(L, toclose);
- return 1;
+ int toclose;
+ if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
+ if (lua_isnil(L, 1)) { /* no file name? */
+ lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
+ lua_replace(L, 1); /* put it at index 1 */
+ tofile(L); /* check that it's a valid file handle */
+ toclose = 0; /* do not close it after iteration */
+ }
+ else { /* open a new file */
+ const char *filename = luaL_checkstring(L, 1);
+ opencheck(L, filename, "r");
+ lua_replace(L, 1); /* put file at index 1 */
+ toclose = 1; /* close it after iteration */
+ }
+ aux_lines(L, toclose);
+ return 1;
}
@@ -347,239 +347,239 @@ static int io_lines (lua_State *L) {
static int read_number (lua_State *L, FILE *f) {
- lua_Number d;
- if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
- lua_pushnumber(L, d);
- return 1;
- }
- else {
- lua_pushnil(L); /* "result" to be removed */
- return 0; /* read fails */
- }
+ lua_Number d;
+ if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
+ lua_pushnumber(L, d);
+ return 1;
+ }
+ else {
+ lua_pushnil(L); /* "result" to be removed */
+ return 0; /* read fails */
+ }
}
static int test_eof (lua_State *L, FILE *f) {
- int c = getc(f);
- ungetc(c, f);
- lua_pushlstring(L, NULL, 0);
- return (c != EOF);
+ int c = getc(f);
+ ungetc(c, f);
+ lua_pushlstring(L, NULL, 0);
+ return (c != EOF);
}
static int read_line (lua_State *L, FILE *f, int chop) {
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- for (;;) {
- size_t l;
- char *p = luaL_prepbuffer(&b);
- if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
- luaL_pushresult(&b); /* close buffer */
- return (lua_rawlen(L, -1) > 0); /* check whether read something */
- }
- l = strlen(p);
- if (l == 0 || p[l-1] != '\n')
- luaL_addsize(&b, l);
- else {
- luaL_addsize(&b, l - chop); /* chop 'eol' if needed */
- luaL_pushresult(&b); /* close buffer */
- return 1; /* read at least an `eol' */
- }
- }
-}
-
-
-#define MAX_SIZE_T (~(size_t)0)
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ for (;;) {
+ size_t l;
+ char *p = luaL_prepbuffer(&b);
+ if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
+ luaL_pushresult(&b); /* close buffer */
+ return (lua_rawlen(L, -1) > 0); /* check whether read something */
+ }
+ l = strlen(p);
+ if (l == 0 || p[l-1] != '\n')
+ luaL_addsize(&b, l);
+ else {
+ luaL_addsize(&b, l - chop); /* chop 'eol' if needed */
+ luaL_pushresult(&b); /* close buffer */
+ return 1; /* read at least an `eol' */
+ }
+ }
+}
+
+
+#define MAX_SIZE_T (~(size_t)0)
static void read_all (lua_State *L, FILE *f) {
- size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- for (;;) {
- char *p = luaL_prepbuffsize(&b, rlen);
- size_t nr = fread(p, sizeof(char), rlen, f);
- luaL_addsize(&b, nr);
- if (nr < rlen) break; /* eof? */
- else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
- rlen *= 2; /* double buffer size at each iteration */
- }
- luaL_pushresult(&b); /* close buffer */
+ size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ for (;;) {
+ char *p = luaL_prepbuffsize(&b, rlen);
+ size_t nr = fread(p, sizeof(char), rlen, f);
+ luaL_addsize(&b, nr);
+ if (nr < rlen) break; /* eof? */
+ else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
+ rlen *= 2; /* double buffer size at each iteration */
+ }
+ luaL_pushresult(&b); /* close buffer */
}
static int read_chars (lua_State *L, FILE *f, size_t n) {
- size_t nr; /* number of chars actually read */
- char *p;
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
- nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
- luaL_addsize(&b, nr);
- luaL_pushresult(&b); /* close buffer */
- return (nr > 0); /* true iff read something */
+ size_t nr; /* number of chars actually read */
+ char *p;
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
+ nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
+ luaL_addsize(&b, nr);
+ luaL_pushresult(&b); /* close buffer */
+ return (nr > 0); /* true iff read something */
}
static int g_read (lua_State *L, FILE *f, int first) {
- int nargs = lua_gettop(L) - 1;
- int success;
- int n;
- clearerr(f);
- if (nargs == 0) { /* no arguments? */
- success = read_line(L, f, 1);
- n = first+1; /* to return 1 result */
- }
- else { /* ensure stack space for all results and for auxlib's buffer */
- luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
- success = 1;
- for (n = first; nargs-- && success; n++) {
- if (lua_type(L, n) == LUA_TNUMBER) {
- size_t l = (size_t)lua_tointeger(L, n);
- success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
- }
- else {
- const char *p = lua_tostring(L, n);
- luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
- switch (p[1]) {
- case 'n': /* number */
- success = read_number(L, f);
- break;
- case 'l': /* line */
- success = read_line(L, f, 1);
- break;
- case 'L': /* line with end-of-line */
- success = read_line(L, f, 0);
- break;
- case 'a': /* file */
- read_all(L, f); /* read entire file */
- success = 1; /* always success */
- break;
- default:
- return luaL_argerror(L, n, "invalid format");
- }
- }
- }
- }
- if (ferror(f))
- return luaL_fileresult(L, 0, NULL);
- if (!success) {
- lua_pop(L, 1); /* remove last result */
- lua_pushnil(L); /* push nil instead */
- }
- return n - first;
+ int nargs = lua_gettop(L) - 1;
+ int success;
+ int n;
+ clearerr(f);
+ if (nargs == 0) { /* no arguments? */
+ success = read_line(L, f, 1);
+ n = first+1; /* to return 1 result */
+ }
+ else { /* ensure stack space for all results and for auxlib's buffer */
+ luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
+ success = 1;
+ for (n = first; nargs-- && success; n++) {
+ if (lua_type(L, n) == LUA_TNUMBER) {
+ size_t l = (size_t)lua_tointeger(L, n);
+ success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
+ }
+ else {
+ const char *p = lua_tostring(L, n);
+ luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
+ switch (p[1]) {
+ case 'n': /* number */
+ success = read_number(L, f);
+ break;
+ case 'l': /* line */
+ success = read_line(L, f, 1);
+ break;
+ case 'L': /* line with end-of-line */
+ success = read_line(L, f, 0);
+ break;
+ case 'a': /* file */
+ read_all(L, f); /* read entire file */
+ success = 1; /* always success */
+ break;
+ default:
+ return luaL_argerror(L, n, "invalid format");
+ }
+ }
+ }
+ }
+ if (ferror(f))
+ return luaL_fileresult(L, 0, NULL);
+ if (!success) {
+ lua_pop(L, 1); /* remove last result */
+ lua_pushnil(L); /* push nil instead */
+ }
+ return n - first;
}
static int io_read (lua_State *L) {
- return g_read(L, getiofile(L, IO_INPUT), 1);
+ return g_read(L, getiofile(L, IO_INPUT), 1);
}
static int f_read (lua_State *L) {
- return g_read(L, tofile(L), 2);
+ return g_read(L, tofile(L), 2);
}
static int io_readline (lua_State *L) {
- LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
- int i;
- int n = (int)lua_tointeger(L, lua_upvalueindex(2));
- if (isclosed(p)) /* file is already closed? */
- return luaL_error(L, "file is already closed");
- lua_settop(L , 1);
- for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
- lua_pushvalue(L, lua_upvalueindex(3 + i));
- n = g_read(L, p->f, 2); /* 'n' is number of results */
- lua_assert(n > 0); /* should return at least a nil */
- if (!lua_isnil(L, -n)) /* read at least one value? */
- return n; /* return them */
- else { /* first result is nil: EOF or error */
- if (n > 1) { /* is there error information? */
- /* 2nd result is error message */
- return luaL_error(L, "%s", lua_tostring(L, -n + 1));
- }
- if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
- lua_settop(L, 0);
- lua_pushvalue(L, lua_upvalueindex(1));
- aux_close(L); /* close it */
- }
- return 0;
- }
+ LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
+ int i;
+ int n = (int)lua_tointeger(L, lua_upvalueindex(2));
+ if (isclosed(p)) /* file is already closed? */
+ return luaL_error(L, "file is already closed");
+ lua_settop(L , 1);
+ for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
+ lua_pushvalue(L, lua_upvalueindex(3 + i));
+ n = g_read(L, p->f, 2); /* 'n' is number of results */
+ lua_assert(n > 0); /* should return at least a nil */
+ if (!lua_isnil(L, -n)) /* read at least one value? */
+ return n; /* return them */
+ else { /* first result is nil: EOF or error */
+ if (n > 1) { /* is there error information? */
+ /* 2nd result is error message */
+ return luaL_error(L, "%s", lua_tostring(L, -n + 1));
+ }
+ if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
+ lua_settop(L, 0);
+ lua_pushvalue(L, lua_upvalueindex(1));
+ aux_close(L); /* close it */
+ }
+ return 0;
+ }
}
/* }====================================================== */
static int g_write (lua_State *L, FILE *f, int arg) {
- int nargs = lua_gettop(L) - arg;
- int status = 1;
- for (; nargs--; arg++) {
- if (lua_type(L, arg) == LUA_TNUMBER) {
- /* optimization: could be done exactly as for strings */
- status = status &&
- fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
- }
- else {
- size_t l;
- const char *s = luaL_checklstring(L, arg, &l);
- status = status && (fwrite(s, sizeof(char), l, f) == l);
- }
- }
- if (status) return 1; /* file handle already on stack top */
- else return luaL_fileresult(L, status, NULL);
+ int nargs = lua_gettop(L) - arg;
+ int status = 1;
+ for (; nargs--; arg++) {
+ if (lua_type(L, arg) == LUA_TNUMBER) {
+ /* optimization: could be done exactly as for strings */
+ status = status &&
+ fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
+ }
+ else {
+ size_t l;
+ const char *s = luaL_checklstring(L, arg, &l);
+ status = status && (fwrite(s, sizeof(char), l, f) == l);
+ }
+ }
+ if (status) return 1; /* file handle already on stack top */
+ else return luaL_fileresult(L, status, NULL);
}
static int io_write (lua_State *L) {
- return g_write(L, getiofile(L, IO_OUTPUT), 1);
+ return g_write(L, getiofile(L, IO_OUTPUT), 1);
}
static int f_write (lua_State *L) {
- FILE *f = tofile(L);
- lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
- return g_write(L, f, 2);
+ FILE *f = tofile(L);
+ lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
+ return g_write(L, f, 2);
}
static int f_seek (lua_State *L) {
- static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
- static const char *const modenames[] = {"set", "cur", "end", NULL};
- FILE *f = tofile(L);
- int op = luaL_checkoption(L, 2, "cur", modenames);
- lua_Number p3 = luaL_optnumber(L, 3, 0);
- l_seeknum offset = (l_seeknum)p3;
- luaL_argcheck(L, (lua_Number)offset == p3, 3,
- "not an integer in proper range");
- op = l_fseek(f, offset, mode[op]);
- if (op)
- return luaL_fileresult(L, 0, NULL); /* error */
- else {
- lua_pushnumber(L, (lua_Number)(1.0*l_ftell(f)));
- return 1;
- }
+ static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
+ static const char *const modenames[] = {"set", "cur", "end", NULL};
+ FILE *f = tofile(L);
+ int op = luaL_checkoption(L, 2, "cur", modenames);
+ lua_Number p3 = luaL_optnumber(L, 3, 0);
+ l_seeknum offset = (l_seeknum)p3;
+ luaL_argcheck(L, (lua_Number)offset == p3, 3,
+ "not an integer in proper range");
+ op = l_fseek(f, offset, mode[op]);
+ if (op)
+ return luaL_fileresult(L, 0, NULL); /* error */
+ else {
+ lua_pushnumber(L, (lua_Number)(1.0*l_ftell(f)));
+ return 1;
+ }
}
static int f_setvbuf (lua_State *L) {
- static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
- static const char *const modenames[] = {"no", "full", "line", NULL};
- FILE *f = tofile(L);
- int op = luaL_checkoption(L, 2, NULL, modenames);
- lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
- int res = setvbuf(f, NULL, mode[op], sz);
- return luaL_fileresult(L, res == 0, NULL);
+ static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
+ static const char *const modenames[] = {"no", "full", "line", NULL};
+ FILE *f = tofile(L);
+ int op = luaL_checkoption(L, 2, NULL, modenames);
+ lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
+ int res = setvbuf(f, NULL, mode[op], sz);
+ return luaL_fileresult(L, res == 0, NULL);
}
static int io_flush (lua_State *L) {
- return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
+ return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
}
static int f_flush (lua_State *L) {
- return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
+ return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
}
@@ -587,18 +587,18 @@ static int f_flush (lua_State *L) {
** functions for 'io' library
*/
static const luaL_Reg iolib[] = {
- {"close", io_close},
- {"flush", io_flush},
- {"input", io_input},
- {"lines", io_lines},
- {"open", io_open},
- {"output", io_output},
- {"popen", io_popen},
- {"read", io_read},
- {"tmpfile", io_tmpfile},
- {"type", io_type},
- {"write", io_write},
- {NULL, NULL}
+ {"close", io_close},
+ {"flush", io_flush},
+ {"input", io_input},
+ {"lines", io_lines},
+ {"open", io_open},
+ {"output", io_output},
+ {"popen", io_popen},
+ {"read", io_read},
+ {"tmpfile", io_tmpfile},
+ {"type", io_type},
+ {"write", io_write},
+ {NULL, NULL}
};
@@ -606,25 +606,25 @@ static const luaL_Reg iolib[] = {
** methods for file handles
*/
static const luaL_Reg flib[] = {
- {"close", io_close},
- {"flush", f_flush},
- {"lines", f_lines},
- {"read", f_read},
- {"seek", f_seek},
- {"setvbuf", f_setvbuf},
- {"write", f_write},
- {"__gc", f_gc},
- {"__tostring", f_tostring},
- {NULL, NULL}
+ {"close", io_close},
+ {"flush", f_flush},
+ {"lines", f_lines},
+ {"read", f_read},
+ {"seek", f_seek},
+ {"setvbuf", f_setvbuf},
+ {"write", f_write},
+ {"__gc", f_gc},
+ {"__tostring", f_tostring},
+ {NULL, NULL}
};
static void createmeta (lua_State *L) {
- luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
- lua_pushvalue(L, -1); /* push metatable */
- lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
- luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
- lua_pop(L, 1); /* pop new metatable */
+ luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
+ lua_pushvalue(L, -1); /* push metatable */
+ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
+ luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
+ lua_pop(L, 1); /* pop new metatable */
}
@@ -632,34 +632,33 @@ static void createmeta (lua_State *L) {
** function to (not) close the standard files stdin, stdout, and stderr
*/
static int io_noclose (lua_State *L) {
- LStream *p = tolstream(L);
- p->closef = &io_noclose; /* keep file opened */
- lua_pushnil(L);
- lua_pushliteral(L, "cannot close standard file");
- return 2;
+ LStream *p = tolstream(L);
+ p->closef = &io_noclose; /* keep file opened */
+ lua_pushnil(L);
+ lua_pushliteral(L, "cannot close standard file");
+ return 2;
}
static void createstdfile (lua_State *L, FILE *f, const char *k,
- const char *fname) {
- LStream *p = newprefile(L);
- p->f = f;
- p->closef = &io_noclose;
- if (k != NULL) {
- lua_pushvalue(L, -1);
- lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
- }
- lua_setfield(L, -2, fname); /* add file to module */
+ const char *fname) {
+ LStream *p = newprefile(L);
+ p->f = f;
+ p->closef = &io_noclose;
+ if (k != NULL) {
+ lua_pushvalue(L, -1);
+ lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
+ }
+ lua_setfield(L, -2, fname); /* add file to module */
}
LUAMOD_API int luaopen_io (lua_State *L) {
- luaL_newlib(L, iolib); /* new module */
- createmeta(L);
- /* create (and set) default files */
- createstdfile(L, stdin, IO_INPUT, "stdin");
- createstdfile(L, stdout, IO_OUTPUT, "stdout");
- createstdfile(L, stderr, NULL, "stderr");
- return 1;
+ luaL_newlib(L, iolib); /* new module */
+ createmeta(L);
+ /* create (and set) default files */
+ createstdfile(L, stdin, IO_INPUT, "stdin");
+ createstdfile(L, stdout, IO_OUTPUT, "stdout");
+ createstdfile(L, stderr, NULL, "stderr");
+ return 1;
}
-
diff --git a/src/lib/lua/llex.c b/src/lib/lua/llex.c
index 1a32e348b0b..3a2f0e08409 100644
--- a/src/lib/lua/llex.c
+++ b/src/lib/lua/llex.c
@@ -29,17 +29,17 @@
-#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
+#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
/* ORDER RESERVED */
static const char *const luaX_tokens [] = {
- "and", "break", "do", "else", "elseif",
- "end", "false", "for", "function", "goto", "if",
- "in", "local", "nil", "not", "or", "repeat",
- "return", "then", "true", "until", "while",
- "..", "...", "==", ">=", "<=", "~=", "::", "<eof>",
- "<number>", "<name>", "<string>"
+ "and", "break", "do", "else", "elseif",
+ "end", "false", "for", "function", "goto", "if",
+ "in", "local", "nil", "not", "or", "repeat",
+ "return", "then", "true", "until", "while",
+ "..", "...", "==", ">=", "<=", "~=", "::", "<eof>",
+ "<number>", "<name>", "<string>"
};
@@ -50,69 +50,69 @@ static l_noret lexerror (LexState *ls, const char *msg, int token);
static void save (LexState *ls, int c) {
- Mbuffer *b = ls->buff;
- if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
- size_t newsize;
- if (luaZ_sizebuffer(b) >= MAX_SIZET/2)
- lexerror(ls, "lexical element too long", 0);
- newsize = luaZ_sizebuffer(b) * 2;
- luaZ_resizebuffer(ls->L, b, newsize);
- }
- b->buffer[luaZ_bufflen(b)++] = cast(char, c);
+ Mbuffer *b = ls->buff;
+ if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
+ size_t newsize;
+ if (luaZ_sizebuffer(b) >= MAX_SIZET/2)
+ lexerror(ls, "lexical element too long", 0);
+ newsize = luaZ_sizebuffer(b) * 2;
+ luaZ_resizebuffer(ls->L, b, newsize);
+ }
+ b->buffer[luaZ_bufflen(b)++] = cast(char, c);
}
void luaX_init (lua_State *L) {
- int i;
- for (i=0; i<NUM_RESERVED; i++) {
- TString *ts = luaS_new(L, luaX_tokens[i]);
- luaS_fix(ts); /* reserved words are never collected */
- ts->tsv.extra = cast_byte(i+1); /* reserved word */
- }
+ int i;
+ for (i=0; i<NUM_RESERVED; i++) {
+ TString *ts = luaS_new(L, luaX_tokens[i]);
+ luaS_fix(ts); /* reserved words are never collected */
+ ts->tsv.extra = cast_byte(i+1); /* reserved word */
+ }
}
const char *luaX_token2str (LexState *ls, int token) {
- if (token < FIRST_RESERVED) { /* single-byte symbols? */
- lua_assert(token == cast(unsigned char, token));
- return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
- luaO_pushfstring(ls->L, "char(%d)", token);
- }
- else {
- const char *s = luaX_tokens[token - FIRST_RESERVED];
- if (token < TK_EOS) /* fixed format (symbols and reserved words)? */
- return luaO_pushfstring(ls->L, LUA_QS, s);
- else /* names, strings, and numerals */
- return s;
- }
+ if (token < FIRST_RESERVED) { /* single-byte symbols? */
+ lua_assert(token == cast(unsigned char, token));
+ return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
+ luaO_pushfstring(ls->L, "char(%d)", token);
+ }
+ else {
+ const char *s = luaX_tokens[token - FIRST_RESERVED];
+ if (token < TK_EOS) /* fixed format (symbols and reserved words)? */
+ return luaO_pushfstring(ls->L, LUA_QS, s);
+ else /* names, strings, and numerals */
+ return s;
+ }
}
static const char *txtToken (LexState *ls, int token) {
- switch (token) {
- case TK_NAME:
- case TK_STRING:
- case TK_NUMBER:
- save(ls, '\0');
- return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff));
- default:
- return luaX_token2str(ls, token);
- }
+ switch (token) {
+ case TK_NAME:
+ case TK_STRING:
+ case TK_NUMBER:
+ save(ls, '\0');
+ return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff));
+ default:
+ return luaX_token2str(ls, token);
+ }
}
static l_noret lexerror (LexState *ls, const char *msg, int token) {
- char buff[LUA_IDSIZE];
- luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE);
- msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
- if (token)
- luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
- luaD_throw(ls->L, LUA_ERRSYNTAX);
+ char buff[LUA_IDSIZE];
+ luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE);
+ msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
+ if (token)
+ luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
+ luaD_throw(ls->L, LUA_ERRSYNTAX);
}
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
- lexerror(ls, msg, ls->t.token);
+ lexerror(ls, msg, ls->t.token);
}
@@ -122,19 +122,19 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
** (by that time it should be anchored in function's prototype)
*/
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
- lua_State *L = ls->L;
- TValue *o; /* entry for `str' */
- TString *ts = luaS_newlstr(L, str, l); /* create new string */
- setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */
- o = luaH_set(L, ls->fs->h, L->top - 1);
- if (ttisnil(o)) { /* not in use yet? (see 'addK') */
- /* boolean value does not need GC barrier;
- table has no metatable, so it does not need to invalidate cache */
- setbvalue(o, 1); /* t[string] = true */
- luaC_checkGC(L);
- }
- L->top--; /* remove string from stack */
- return ts;
+ lua_State *L = ls->L;
+ TValue *o; /* entry for `str' */
+ TString *ts = luaS_newlstr(L, str, l); /* create new string */
+ setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */
+ o = luaH_set(L, ls->fs->h, L->top - 1);
+ if (ttisnil(o)) { /* not in use yet? (see 'addK') */
+ /* boolean value does not need GC barrier;
+ table has no metatable, so it does not need to invalidate cache */
+ setbvalue(o, 1); /* t[string] = true */
+ luaC_checkGC(L);
+ }
+ L->top--; /* remove string from stack */
+ return ts;
}
@@ -143,30 +143,30 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
** \n, \r, \n\r, or \r\n)
*/
static void inclinenumber (LexState *ls) {
- int old = ls->current;
- lua_assert(currIsNewline(ls));
- next(ls); /* skip `\n' or `\r' */
- if (currIsNewline(ls) && ls->current != old)
- next(ls); /* skip `\n\r' or `\r\n' */
- if (++ls->linenumber >= MAX_INT)
- luaX_syntaxerror(ls, "chunk has too many lines");
+ int old = ls->current;
+ lua_assert(currIsNewline(ls));
+ next(ls); /* skip `\n' or `\r' */
+ if (currIsNewline(ls) && ls->current != old)
+ next(ls); /* skip `\n\r' or `\r\n' */
+ if (++ls->linenumber >= MAX_INT)
+ luaX_syntaxerror(ls, "chunk has too many lines");
}
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
- int firstchar) {
- ls->decpoint = '.';
- ls->L = L;
- ls->current = firstchar;
- ls->lookahead.token = TK_EOS; /* no look-ahead token */
- ls->z = z;
- ls->fs = NULL;
- ls->linenumber = 1;
- ls->lastline = 1;
- ls->source = source;
- ls->envn = luaS_new(L, LUA_ENV); /* create env name */
- luaS_fix(ls->envn); /* never collect this name */
- luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
+ int firstchar) {
+ ls->decpoint = '.';
+ ls->L = L;
+ ls->current = firstchar;
+ ls->lookahead.token = TK_EOS; /* no look-ahead token */
+ ls->z = z;
+ ls->fs = NULL;
+ ls->linenumber = 1;
+ ls->lastline = 1;
+ ls->source = source;
+ ls->envn = luaS_new(L, LUA_ENV); /* create env name */
+ luaS_fix(ls->envn); /* never collect this name */
+ luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
}
@@ -180,10 +180,10 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
static int check_next (LexState *ls, const char *set) {
- if (ls->current == '\0' || !strchr(set, ls->current))
- return 0;
- save_and_next(ls);
- return 1;
+ if (ls->current == '\0' || !strchr(set, ls->current))
+ return 0;
+ save_and_next(ls);
+ return 1;
}
@@ -191,33 +191,33 @@ static int check_next (LexState *ls, const char *set) {
** change all characters 'from' in buffer to 'to'
*/
static void buffreplace (LexState *ls, char from, char to) {
- size_t n = luaZ_bufflen(ls->buff);
- char *p = luaZ_buffer(ls->buff);
- while (n--)
- if (p[n] == from) p[n] = to;
+ size_t n = luaZ_bufflen(ls->buff);
+ char *p = luaZ_buffer(ls->buff);
+ while (n--)
+ if (p[n] == from) p[n] = to;
}
#if !defined(getlocaledecpoint)
-#define getlocaledecpoint() (localeconv()->decimal_point[0])
+#define getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
-#define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
+#define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
/*
** in case of format error, try to change decimal point separator to
** the one defined in the current locale and check again
*/
static void trydecpoint (LexState *ls, SemInfo *seminfo) {
- char old = ls->decpoint;
- ls->decpoint = getlocaledecpoint();
- buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
- if (!buff2d(ls->buff, &seminfo->r)) {
- /* format error with correct decimal point: no more options */
- buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
- lexerror(ls, "malformed number", TK_NUMBER);
- }
+ char old = ls->decpoint;
+ ls->decpoint = getlocaledecpoint();
+ buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
+ if (!buff2d(ls->buff, &seminfo->r)) {
+ /* format error with correct decimal point: no more options */
+ buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
+ lexerror(ls, "malformed number", TK_NUMBER);
+ }
}
@@ -227,23 +227,23 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
** will reject ill-formed numerals.
*/
static void read_numeral (LexState *ls, SemInfo *seminfo) {
- const char *expo = "Ee";
- int first = ls->current;
- lua_assert(lisdigit(ls->current));
- save_and_next(ls);
- if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
- expo = "Pp";
- for (;;) {
- if (check_next(ls, expo)) /* exponent part? */
- check_next(ls, "+-"); /* optional exponent sign */
- if (lisxdigit(ls->current) || ls->current == '.')
- save_and_next(ls);
- else break;
- }
- save(ls, '\0');
- buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
- if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
- trydecpoint(ls, seminfo); /* try to update decimal point separator */
+ const char *expo = "Ee";
+ int first = ls->current;
+ lua_assert(lisdigit(ls->current));
+ save_and_next(ls);
+ if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
+ expo = "Pp";
+ for (;;) {
+ if (check_next(ls, expo)) /* exponent part? */
+ check_next(ls, "+-"); /* optional exponent sign */
+ if (lisxdigit(ls->current) || ls->current == '.')
+ save_and_next(ls);
+ else break;
+ }
+ save(ls, '\0');
+ buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
+ if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
+ trydecpoint(ls, seminfo); /* try to update decimal point separator */
}
@@ -252,276 +252,275 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
** -1 if sequence is malformed
*/
static int skip_sep (LexState *ls) {
- int count = 0;
- int s = ls->current;
- lua_assert(s == '[' || s == ']');
- save_and_next(ls);
- while (ls->current == '=') {
- save_and_next(ls);
- count++;
- }
- return (ls->current == s) ? count : (-count) - 1;
+ int count = 0;
+ int s = ls->current;
+ lua_assert(s == '[' || s == ']');
+ save_and_next(ls);
+ while (ls->current == '=') {
+ save_and_next(ls);
+ count++;
+ }
+ return (ls->current == s) ? count : (-count) - 1;
}
static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
- save_and_next(ls); /* skip 2nd `[' */
- if (currIsNewline(ls)) /* string starts with a newline? */
- inclinenumber(ls); /* skip it */
- for (;;) {
- switch (ls->current) {
- case EOZ:
- lexerror(ls, (seminfo) ? "unfinished long string" :
- "unfinished long comment", TK_EOS);
- break; /* to avoid warnings */
- case ']': {
- if (skip_sep(ls) == sep) {
- save_and_next(ls); /* skip 2nd `]' */
- goto endloop;
- }
- break;
- }
- case '\n': case '\r': {
- save(ls, '\n');
- inclinenumber(ls);
- if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
- break;
- }
- default: {
- if (seminfo) save_and_next(ls);
- else next(ls);
- }
- }
- } endloop:
- if (seminfo)
- seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
- luaZ_bufflen(ls->buff) - 2*(2 + sep));
+ save_and_next(ls); /* skip 2nd `[' */
+ if (currIsNewline(ls)) /* string starts with a newline? */
+ inclinenumber(ls); /* skip it */
+ for (;;) {
+ switch (ls->current) {
+ case EOZ:
+ lexerror(ls, (seminfo) ? "unfinished long string" :
+ "unfinished long comment", TK_EOS);
+ break; /* to avoid warnings */
+ case ']': {
+ if (skip_sep(ls) == sep) {
+ save_and_next(ls); /* skip 2nd `]' */
+ goto endloop;
+ }
+ break;
+ }
+ case '\n': case '\r': {
+ save(ls, '\n');
+ inclinenumber(ls);
+ if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
+ break;
+ }
+ default: {
+ if (seminfo) save_and_next(ls);
+ else next(ls);
+ }
+ }
+ } endloop:
+ if (seminfo)
+ seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
+ luaZ_bufflen(ls->buff) - 2*(2 + sep));
}
static void escerror (LexState *ls, int *c, int n, const char *msg) {
- int i;
- luaZ_resetbuffer(ls->buff); /* prepare error message */
- save(ls, '\\');
- for (i = 0; i < n && c[i] != EOZ; i++)
- save(ls, c[i]);
- lexerror(ls, msg, TK_STRING);
+ int i;
+ luaZ_resetbuffer(ls->buff); /* prepare error message */
+ save(ls, '\\');
+ for (i = 0; i < n && c[i] != EOZ; i++)
+ save(ls, c[i]);
+ lexerror(ls, msg, TK_STRING);
}
static int readhexaesc (LexState *ls) {
- int c[3], i; /* keep input for error message */
- int r = 0; /* result accumulator */
- c[0] = 'x'; /* for error message */
- for (i = 1; i < 3; i++) { /* read two hexadecimal digits */
- c[i] = next(ls);
- if (!lisxdigit(c[i]))
- escerror(ls, c, i + 1, "hexadecimal digit expected");
- r = (r << 4) + luaO_hexavalue(c[i]);
- }
- return r;
+ int c[3], i; /* keep input for error message */
+ int r = 0; /* result accumulator */
+ c[0] = 'x'; /* for error message */
+ for (i = 1; i < 3; i++) { /* read two hexadecimal digits */
+ c[i] = next(ls);
+ if (!lisxdigit(c[i]))
+ escerror(ls, c, i + 1, "hexadecimal digit expected");
+ r = (r << 4) + luaO_hexavalue(c[i]);
+ }
+ return r;
}
static int readdecesc (LexState *ls) {
- int c[3], i;
- int r = 0; /* result accumulator */
- for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */
- c[i] = ls->current;
- r = 10*r + c[i] - '0';
- next(ls);
- }
- if (r > UCHAR_MAX)
- escerror(ls, c, i, "decimal escape too large");
- return r;
+ int c[3], i;
+ int r = 0; /* result accumulator */
+ for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */
+ c[i] = ls->current;
+ r = 10*r + c[i] - '0';
+ next(ls);
+ }
+ if (r > UCHAR_MAX)
+ escerror(ls, c, i, "decimal escape too large");
+ return r;
}
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
- save_and_next(ls); /* keep delimiter (for error messages) */
- while (ls->current != del) {
- switch (ls->current) {
- case EOZ:
- lexerror(ls, "unfinished string", TK_EOS);
- break; /* to avoid warnings */
- case '\n':
- case '\r':
- lexerror(ls, "unfinished string", TK_STRING);
- break; /* to avoid warnings */
- case '\\': { /* escape sequences */
- int c; /* final character to be saved */
- next(ls); /* do not save the `\' */
- switch (ls->current) {
- case 'a': c = '\a'; goto read_save;
- case 'b': c = '\b'; goto read_save;
- case 'f': c = '\f'; goto read_save;
- case 'n': c = '\n'; goto read_save;
- case 'r': c = '\r'; goto read_save;
- case 't': c = '\t'; goto read_save;
- case 'v': c = '\v'; goto read_save;
- case 'x': c = readhexaesc(ls); goto read_save;
- case '\n': case '\r':
- inclinenumber(ls); c = '\n'; goto only_save;
- case '\\': case '\"': case '\'':
- c = ls->current; goto read_save;
- case EOZ: goto no_save; /* will raise an error next loop */
- case 'z': { /* zap following span of spaces */
- next(ls); /* skip the 'z' */
- while (lisspace(ls->current)) {
- if (currIsNewline(ls)) inclinenumber(ls);
- else next(ls);
- }
- goto no_save;
- }
- default: {
- if (!lisdigit(ls->current))
- escerror(ls, &ls->current, 1, "invalid escape sequence");
- /* digital escape \ddd */
- c = readdecesc(ls);
- goto only_save;
- }
- }
- read_save: next(ls); /* read next character */
- only_save: save(ls, c); /* save 'c' */
- no_save: break;
- }
- default:
- save_and_next(ls);
- }
- }
- save_and_next(ls); /* skip delimiter */
- seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
- luaZ_bufflen(ls->buff) - 2);
+ save_and_next(ls); /* keep delimiter (for error messages) */
+ while (ls->current != del) {
+ switch (ls->current) {
+ case EOZ:
+ lexerror(ls, "unfinished string", TK_EOS);
+ break; /* to avoid warnings */
+ case '\n':
+ case '\r':
+ lexerror(ls, "unfinished string", TK_STRING);
+ break; /* to avoid warnings */
+ case '\\': { /* escape sequences */
+ int c; /* final character to be saved */
+ next(ls); /* do not save the `\' */
+ switch (ls->current) {
+ case 'a': c = '\a'; goto read_save;
+ case 'b': c = '\b'; goto read_save;
+ case 'f': c = '\f'; goto read_save;
+ case 'n': c = '\n'; goto read_save;
+ case 'r': c = '\r'; goto read_save;
+ case 't': c = '\t'; goto read_save;
+ case 'v': c = '\v'; goto read_save;
+ case 'x': c = readhexaesc(ls); goto read_save;
+ case '\n': case '\r':
+ inclinenumber(ls); c = '\n'; goto only_save;
+ case '\\': case '\"': case '\'':
+ c = ls->current; goto read_save;
+ case EOZ: goto no_save; /* will raise an error next loop */
+ case 'z': { /* zap following span of spaces */
+ next(ls); /* skip the 'z' */
+ while (lisspace(ls->current)) {
+ if (currIsNewline(ls)) inclinenumber(ls);
+ else next(ls);
+ }
+ goto no_save;
+ }
+ default: {
+ if (!lisdigit(ls->current))
+ escerror(ls, &ls->current, 1, "invalid escape sequence");
+ /* digital escape \ddd */
+ c = readdecesc(ls);
+ goto only_save;
+ }
+ }
+ read_save: next(ls); /* read next character */
+ only_save: save(ls, c); /* save 'c' */
+ no_save: break;
+ }
+ default:
+ save_and_next(ls);
+ }
+ }
+ save_and_next(ls); /* skip delimiter */
+ seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
+ luaZ_bufflen(ls->buff) - 2);
}
static int llex (LexState *ls, SemInfo *seminfo) {
- luaZ_resetbuffer(ls->buff);
- for (;;) {
- switch (ls->current) {
- case '\n': case '\r': { /* line breaks */
- inclinenumber(ls);
- break;
- }
- case ' ': case '\f': case '\t': case '\v': { /* spaces */
- next(ls);
- break;
- }
- case '-': { /* '-' or '--' (comment) */
- next(ls);
- if (ls->current != '-') return '-';
- /* else is a comment */
- next(ls);
- if (ls->current == '[') { /* long comment? */
- int sep = skip_sep(ls);
- luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
- if (sep >= 0) {
- read_long_string(ls, NULL, sep); /* skip long comment */
- luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */
- break;
- }
- }
- /* else short comment */
- while (!currIsNewline(ls) && ls->current != EOZ)
- next(ls); /* skip until end of line (or end of file) */
- break;
- }
- case '[': { /* long string or simply '[' */
- int sep = skip_sep(ls);
- if (sep >= 0) {
- read_long_string(ls, seminfo, sep);
- return TK_STRING;
- }
- else if (sep == -1) return '[';
- else lexerror(ls, "invalid long string delimiter", TK_STRING);
- }
- case '=': {
- next(ls);
- if (ls->current != '=') return '=';
- else { next(ls); return TK_EQ; }
- }
- case '<': {
- next(ls);
- if (ls->current != '=') return '<';
- else { next(ls); return TK_LE; }
- }
- case '>': {
- next(ls);
- if (ls->current != '=') return '>';
- else { next(ls); return TK_GE; }
- }
- case '~': {
- next(ls);
- if (ls->current != '=') return '~';
- else { next(ls); return TK_NE; }
- }
- case ':': {
- next(ls);
- if (ls->current != ':') return ':';
- else { next(ls); return TK_DBCOLON; }
- }
- case '"': case '\'': { /* short literal strings */
- read_string(ls, ls->current, seminfo);
- return TK_STRING;
- }
- case '.': { /* '.', '..', '...', or number */
- save_and_next(ls);
- if (check_next(ls, ".")) {
- if (check_next(ls, "."))
- return TK_DOTS; /* '...' */
- else return TK_CONCAT; /* '..' */
- }
- else if (!lisdigit(ls->current)) return '.';
- /* else go through */
- }
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9': {
- read_numeral(ls, seminfo);
- return TK_NUMBER;
- }
- case EOZ: {
- return TK_EOS;
- }
- default: {
- if (lislalpha(ls->current)) { /* identifier or reserved word? */
- TString *ts;
- do {
- save_and_next(ls);
- } while (lislalnum(ls->current));
- ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
- luaZ_bufflen(ls->buff));
- seminfo->ts = ts;
- if (isreserved(ts)) /* reserved word? */
- return ts->tsv.extra - 1 + FIRST_RESERVED;
- else {
- return TK_NAME;
- }
- }
- else { /* single-char tokens (+ - / ...) */
- int c = ls->current;
- next(ls);
- return c;
- }
- }
- }
- }
+ luaZ_resetbuffer(ls->buff);
+ for (;;) {
+ switch (ls->current) {
+ case '\n': case '\r': { /* line breaks */
+ inclinenumber(ls);
+ break;
+ }
+ case ' ': case '\f': case '\t': case '\v': { /* spaces */
+ next(ls);
+ break;
+ }
+ case '-': { /* '-' or '--' (comment) */
+ next(ls);
+ if (ls->current != '-') return '-';
+ /* else is a comment */
+ next(ls);
+ if (ls->current == '[') { /* long comment? */
+ int sep = skip_sep(ls);
+ luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
+ if (sep >= 0) {
+ read_long_string(ls, NULL, sep); /* skip long comment */
+ luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */
+ break;
+ }
+ }
+ /* else short comment */
+ while (!currIsNewline(ls) && ls->current != EOZ)
+ next(ls); /* skip until end of line (or end of file) */
+ break;
+ }
+ case '[': { /* long string or simply '[' */
+ int sep = skip_sep(ls);
+ if (sep >= 0) {
+ read_long_string(ls, seminfo, sep);
+ return TK_STRING;
+ }
+ else if (sep == -1) return '[';
+ else lexerror(ls, "invalid long string delimiter", TK_STRING);
+ }
+ case '=': {
+ next(ls);
+ if (ls->current != '=') return '=';
+ else { next(ls); return TK_EQ; }
+ }
+ case '<': {
+ next(ls);
+ if (ls->current != '=') return '<';
+ else { next(ls); return TK_LE; }
+ }
+ case '>': {
+ next(ls);
+ if (ls->current != '=') return '>';
+ else { next(ls); return TK_GE; }
+ }
+ case '~': {
+ next(ls);
+ if (ls->current != '=') return '~';
+ else { next(ls); return TK_NE; }
+ }
+ case ':': {
+ next(ls);
+ if (ls->current != ':') return ':';
+ else { next(ls); return TK_DBCOLON; }
+ }
+ case '"': case '\'': { /* short literal strings */
+ read_string(ls, ls->current, seminfo);
+ return TK_STRING;
+ }
+ case '.': { /* '.', '..', '...', or number */
+ save_and_next(ls);
+ if (check_next(ls, ".")) {
+ if (check_next(ls, "."))
+ return TK_DOTS; /* '...' */
+ else return TK_CONCAT; /* '..' */
+ }
+ else if (!lisdigit(ls->current)) return '.';
+ /* else go through */
+ }
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9': {
+ read_numeral(ls, seminfo);
+ return TK_NUMBER;
+ }
+ case EOZ: {
+ return TK_EOS;
+ }
+ default: {
+ if (lislalpha(ls->current)) { /* identifier or reserved word? */
+ TString *ts;
+ do {
+ save_and_next(ls);
+ } while (lislalnum(ls->current));
+ ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
+ luaZ_bufflen(ls->buff));
+ seminfo->ts = ts;
+ if (isreserved(ts)) /* reserved word? */
+ return ts->tsv.extra - 1 + FIRST_RESERVED;
+ else {
+ return TK_NAME;
+ }
+ }
+ else { /* single-char tokens (+ - / ...) */
+ int c = ls->current;
+ next(ls);
+ return c;
+ }
+ }
+ }
+ }
}
void luaX_next (LexState *ls) {
- ls->lastline = ls->linenumber;
- if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
- ls->t = ls->lookahead; /* use this one */
- ls->lookahead.token = TK_EOS; /* and discharge it */
- }
- else
- ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
+ ls->lastline = ls->linenumber;
+ if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
+ ls->t = ls->lookahead; /* use this one */
+ ls->lookahead.token = TK_EOS; /* and discharge it */
+ }
+ else
+ ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
}
int luaX_lookahead (LexState *ls) {
- lua_assert(ls->lookahead.token == TK_EOS);
- ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
- return ls->lookahead.token;
+ lua_assert(ls->lookahead.token == TK_EOS);
+ ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
+ return ls->lookahead.token;
}
-
diff --git a/src/lib/lua/llex.h b/src/lib/lua/llex.h
index 9ca8a29948c..40f2972d0ce 100644
--- a/src/lib/lua/llex.h
+++ b/src/lib/lua/llex.h
@@ -11,7 +11,7 @@
#include "lzio.h"
-#define FIRST_RESERVED 257
+#define FIRST_RESERVED 257
@@ -20,54 +20,54 @@
* grep "ORDER RESERVED"
*/
enum RESERVED {
- /* terminal symbols denoted by reserved words */
- TK_AND = FIRST_RESERVED, TK_BREAK,
- TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
- TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
- TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
- /* other terminal symbols */
- TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS,
- TK_NUMBER, TK_NAME, TK_STRING
+ /* terminal symbols denoted by reserved words */
+ TK_AND = FIRST_RESERVED, TK_BREAK,
+ TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
+ TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
+ TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
+ /* other terminal symbols */
+ TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS,
+ TK_NUMBER, TK_NAME, TK_STRING
};
/* number of reserved words */
-#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
+#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
typedef union {
- lua_Number r;
- TString *ts;
+ lua_Number r;
+ TString *ts;
} SemInfo; /* semantics information */
typedef struct Token {
- int token;
- SemInfo seminfo;
+ int token;
+ SemInfo seminfo;
} Token;
/* state of the lexer plus state of the parser when shared by all
functions */
typedef struct LexState {
- int current; /* current character (charint) */
- int linenumber; /* input line counter */
- int lastline; /* line of last token `consumed' */
- Token t; /* current token */
- Token lookahead; /* look ahead token */
- struct FuncState *fs; /* current function (parser) */
- struct lua_State *L;
- ZIO *z; /* input stream */
- Mbuffer *buff; /* buffer for tokens */
- struct Dyndata *dyd; /* dynamic structures used by the parser */
- TString *source; /* current source name */
- TString *envn; /* environment variable name */
- char decpoint; /* locale decimal point */
+ int current; /* current character (charint) */
+ int linenumber; /* input line counter */
+ int lastline; /* line of last token `consumed' */
+ Token t; /* current token */
+ Token lookahead; /* look ahead token */
+ struct FuncState *fs; /* current function (parser) */
+ struct lua_State *L;
+ ZIO *z; /* input stream */
+ Mbuffer *buff; /* buffer for tokens */
+ struct Dyndata *dyd; /* dynamic structures used by the parser */
+ TString *source; /* current source name */
+ TString *envn; /* environment variable name */
+ char decpoint; /* locale decimal point */
} LexState;
LUAI_FUNC void luaX_init (lua_State *L);
LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
- TString *source, int firstchar);
+ TString *source, int firstchar);
LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
LUAI_FUNC void luaX_next (LexState *ls);
LUAI_FUNC int luaX_lookahead (LexState *ls);
diff --git a/src/lib/lua/llimits.h b/src/lib/lua/llimits.h
index 1b8c79bda2b..a502f34aca6 100644
--- a/src/lib/lua/llimits.h
+++ b/src/lib/lua/llimits.h
@@ -27,11 +27,11 @@ typedef LUAI_MEM l_mem;
typedef unsigned char lu_byte;
-#define MAX_SIZET ((size_t)(~(size_t)0)-2)
+#define MAX_SIZET ((size_t)(~(size_t)0)-2)
-#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
+#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
-#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
+#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
@@ -47,7 +47,7 @@ typedef unsigned char lu_byte;
/* type to ensure maximum alignment */
#if !defined(LUAI_USER_ALIGNMENT_T)
-#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
+#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
#endif
typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
@@ -59,13 +59,13 @@ typedef LUAI_UACNUMBER l_uacNumber;
/* internal assertions for in-house debugging */
#if defined(lua_assert)
-#define check_exp(c,e) (lua_assert(c), (e))
+#define check_exp(c,e) (lua_assert(c), (e))
/* to avoid problems with conditions too long */
-#define lua_longassert(c) { if (!(c)) lua_assert(0); }
+#define lua_longassert(c) { if (!(c)) lua_assert(0); }
#else
-#define lua_assert(c) ((void)0)
-#define check_exp(c,e) (e)
-#define lua_longassert(c) ((void)0)
+#define lua_assert(c) ((void)0)
+#define check_exp(c,e) (e)
+#define lua_longassert(c) ((void)0)
#endif
/*
@@ -75,38 +75,38 @@ typedef LUAI_UACNUMBER l_uacNumber;
#if defined(LUA_USE_APICHECK)
#include <assert.h>
-#define luai_apicheck(L,e) assert(e)
+#define luai_apicheck(L,e) assert(e)
#else
-#define luai_apicheck(L,e) lua_assert(e)
+#define luai_apicheck(L,e) lua_assert(e)
#endif
#endif
-#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
+#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
#if !defined(UNUSED)
-#define UNUSED(x) ((void)(x)) /* to avoid warnings */
+#define UNUSED(x) ((void)(x)) /* to avoid warnings */
#endif
-#define cast(t, exp) ((t)(exp))
+#define cast(t, exp) ((t)(exp))
-#define cast_byte(i) cast(lu_byte, (i))
-#define cast_num(i) cast(lua_Number, (i))
-#define cast_int(i) cast(int, (i))
-#define cast_uchar(i) cast(unsigned char, (i))
+#define cast_byte(i) cast(lu_byte, (i))
+#define cast_num(i) cast(lua_Number, (i))
+#define cast_int(i) cast(int, (i))
+#define cast_uchar(i) cast(unsigned char, (i))
/*
** non-return type
*/
#if defined(__GNUC__)
-#define l_noret void __attribute__((noreturn))
+#define l_noret void __attribute__((noreturn))
#elif defined(_MSC_VER)
-#define l_noret void __declspec(noreturn)
+#define l_noret void __declspec(noreturn)
#else
-#define l_noret void
+#define l_noret void
#endif
@@ -116,14 +116,14 @@ typedef LUAI_UACNUMBER l_uacNumber;
** in a program. (Value must fit in an unsigned short int.)
*/
#if !defined(LUAI_MAXCCALLS)
-#define LUAI_MAXCCALLS 200
+#define LUAI_MAXCCALLS 200
#endif
/*
** maximum number of upvalues in a closure (both C and Lua). (Value
** must fit in an unsigned char.)
*/
-#define MAXUPVAL UCHAR_MAX
+#define MAXUPVAL UCHAR_MAX
/*
@@ -135,19 +135,19 @@ typedef lu_int32 Instruction;
/* maximum stack for a Lua function */
-#define MAXSTACK 250
+#define MAXSTACK 250
/* minimum size for the string table (must be power of 2) */
#if !defined(MINSTRTABSIZE)
-#define MINSTRTABSIZE 32
+#define MINSTRTABSIZE 32
#endif
/* minimum size for string buffer */
#if !defined(LUA_MINBUFFER)
-#define LUA_MINBUFFER 32
+#define LUA_MINBUFFER 32
#endif
@@ -167,19 +167,19 @@ typedef lu_int32 Instruction;
** created/deleted/resumed/yielded.
*/
#if !defined(luai_userstateopen)
-#define luai_userstateopen(L) ((void)L)
+#define luai_userstateopen(L) ((void)L)
#endif
#if !defined(luai_userstateclose)
-#define luai_userstateclose(L) ((void)L)
+#define luai_userstateclose(L) ((void)L)
#endif
#if !defined(luai_userstatethread)
-#define luai_userstatethread(L,L1) ((void)L)
+#define luai_userstatethread(L,L1) ((void)L)
#endif
#if !defined(luai_userstatefree)
-#define luai_userstatefree(L,L1) ((void)L)
+#define luai_userstatefree(L,L1) ((void)L)
#endif
#if !defined(luai_userstateresume)
@@ -200,78 +200,78 @@ typedef lu_int32 Instruction;
** both small and large values (outside the range of integers).
*/
-#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */
+#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */
/* trick with Microsoft assembler for X86 */
#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
-#define lua_number2integer(i,n) lua_number2int(i, n)
+#define lua_number2integer(i,n) lua_number2int(i, n)
#define lua_number2unsigned(i,n) \
- {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
+ {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
-#elif defined(LUA_IEEE754TRICK) /* }{ */
+#elif defined(LUA_IEEE754TRICK) /* }{ */
/* the next trick should work on any machine using IEEE754 with
a 32-bit int type */
union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
-#if !defined(LUA_IEEEENDIAN) /* { */
-#define LUAI_EXTRAIEEE \
- static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
-#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
+#if !defined(LUA_IEEEENDIAN) /* { */
+#define LUAI_EXTRAIEEE \
+ static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
+#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
#else
-#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
-#define LUAI_EXTRAIEEE /* empty */
-#endif /* } */
+#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
+#define LUAI_EXTRAIEEE /* empty */
+#endif /* } */
#define lua_number2int32(i,n,t) \
- { LUAI_EXTRAIEEE \
- volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
- (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
+ { LUAI_EXTRAIEEE \
+ volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
+ (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
#define luai_hashnum(i,n) \
- { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
- (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
+ { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
+ (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
-#define lua_number2int(i,n) lua_number2int32(i, n, int)
-#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
+#define lua_number2int(i,n) lua_number2int32(i, n, int)
+#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
/* the trick can be expanded to lua_Integer when it is a 32-bit value */
#if defined(LUA_IEEELL)
-#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
+#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
#endif
-#endif /* } */
+#endif /* } */
/* the following definitions always work, but may be slow */
#if !defined(lua_number2int)
-#define lua_number2int(i,n) ((i)=(int)(n))
+#define lua_number2int(i,n) ((i)=(int)(n))
#endif
#if !defined(lua_number2integer)
-#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
+#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
#endif
-#if !defined(lua_number2unsigned) /* { */
+#if !defined(lua_number2unsigned) /* { */
/* the following definition assures proper modulo behavior */
#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT)
#include <math.h>
-#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
+#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
#define lua_number2unsigned(i,n) \
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
#else
-#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
+#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
#endif
-#endif /* } */
+#endif /* } */
#if !defined(lua_unsigned2number)
/* on several machines, coercion from unsigned to double is slow,
so it may be worth to avoid */
#define lua_unsigned2number(u) \
- (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
+ (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
#endif
@@ -282,8 +282,8 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
#include <math.h>
#define luai_hashnum(i,n) { int e; \
- n = l_mathop(frexp)(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
- lua_number2int(i, n); i += e; }
+ n = l_mathop(frexp)(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
+ lua_number2int(i, n); i += e; }
#endif
@@ -293,14 +293,14 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
** macro to control inclusion of some hard tests on stack reallocation
*/
#if !defined(HARDSTACKTESTS)
-#define condmovestack(L) ((void)0)
+#define condmovestack(L) ((void)0)
#else
/* realloc stack keeping its size */
-#define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
+#define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
#endif
#if !defined(HARDMEMTESTS)
-#define condchangemem(L) condmovestack(L)
+#define condchangemem(L) condmovestack(L)
#else
#define condchangemem(L) \
((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
diff --git a/src/lib/lua/lmathlib.c b/src/lib/lua/lmathlib.c
index a49f1fd25a2..50200907973 100644
--- a/src/lib/lua/lmathlib.c
+++ b/src/lib/lua/lmathlib.c
@@ -18,250 +18,250 @@
#undef PI
-#define PI ((lua_Number)(3.1415926535897932384626433832795))
-#define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0))
+#define PI ((lua_Number)(3.1415926535897932384626433832795))
+#define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0))
static int math_abs (lua_State *L) {
- lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_sin (lua_State *L) {
- lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_sinh (lua_State *L) {
- lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_cos (lua_State *L) {
- lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_cosh (lua_State *L) {
- lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_tan (lua_State *L) {
- lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_tanh (lua_State *L) {
- lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_asin (lua_State *L) {
- lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_acos (lua_State *L) {
- lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_atan (lua_State *L) {
- lua_pushnumber(L, l_mathop(atan)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(atan)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_atan2 (lua_State *L) {
- lua_pushnumber(L, l_mathop(atan2)(luaL_checknumber(L, 1),
- luaL_checknumber(L, 2)));
- return 1;
+ lua_pushnumber(L, l_mathop(atan2)(luaL_checknumber(L, 1),
+ luaL_checknumber(L, 2)));
+ return 1;
}
static int math_ceil (lua_State *L) {
- lua_pushnumber(L, l_mathop(ceil)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(ceil)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_floor (lua_State *L) {
- lua_pushnumber(L, l_mathop(floor)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(floor)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_fmod (lua_State *L) {
- lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),
- luaL_checknumber(L, 2)));
- return 1;
+ lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),
+ luaL_checknumber(L, 2)));
+ return 1;
}
static int math_modf (lua_State *L) {
- lua_Number ip;
- lua_Number fp = l_mathop(modf)(luaL_checknumber(L, 1), &ip);
- lua_pushnumber(L, ip);
- lua_pushnumber(L, fp);
- return 2;
+ lua_Number ip;
+ lua_Number fp = l_mathop(modf)(luaL_checknumber(L, 1), &ip);
+ lua_pushnumber(L, ip);
+ lua_pushnumber(L, fp);
+ return 2;
}
static int math_sqrt (lua_State *L) {
- lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_pow (lua_State *L) {
- lua_Number x = luaL_checknumber(L, 1);
- lua_Number y = luaL_checknumber(L, 2);
- lua_pushnumber(L, l_mathop(pow)(x, y));
- return 1;
+ lua_Number x = luaL_checknumber(L, 1);
+ lua_Number y = luaL_checknumber(L, 2);
+ lua_pushnumber(L, l_mathop(pow)(x, y));
+ return 1;
}
static int math_log (lua_State *L) {
- lua_Number x = luaL_checknumber(L, 1);
- lua_Number res;
- if (lua_isnoneornil(L, 2))
- res = l_mathop(log)(x);
- else {
- lua_Number base = luaL_checknumber(L, 2);
- if (base == (lua_Number)10.0) res = l_mathop(log10)(x);
- else res = l_mathop(log)(x)/l_mathop(log)(base);
- }
- lua_pushnumber(L, res);
- return 1;
+ lua_Number x = luaL_checknumber(L, 1);
+ lua_Number res;
+ if (lua_isnoneornil(L, 2))
+ res = l_mathop(log)(x);
+ else {
+ lua_Number base = luaL_checknumber(L, 2);
+ if (base == (lua_Number)10.0) res = l_mathop(log10)(x);
+ else res = l_mathop(log)(x)/l_mathop(log)(base);
+ }
+ lua_pushnumber(L, res);
+ return 1;
}
#if defined(LUA_COMPAT_LOG10)
static int math_log10 (lua_State *L) {
- lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));
+ return 1;
}
#endif
static int math_exp (lua_State *L) {
- lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));
- return 1;
+ lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));
+ return 1;
}
static int math_deg (lua_State *L) {
- lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
- return 1;
+ lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
+ return 1;
}
static int math_rad (lua_State *L) {
- lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
- return 1;
+ lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
+ return 1;
}
static int math_frexp (lua_State *L) {
- int e;
- lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));
- lua_pushinteger(L, e);
- return 2;
+ int e;
+ lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));
+ lua_pushinteger(L, e);
+ return 2;
}
static int math_ldexp (lua_State *L) {
- lua_Number x = luaL_checknumber(L, 1);
- int ep = luaL_checkint(L, 2);
- lua_pushnumber(L, l_mathop(ldexp)(x, ep));
- return 1;
+ lua_Number x = luaL_checknumber(L, 1);
+ int ep = luaL_checkint(L, 2);
+ lua_pushnumber(L, l_mathop(ldexp)(x, ep));
+ return 1;
}
static int math_min (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- lua_Number dmin = luaL_checknumber(L, 1);
- int i;
- for (i=2; i<=n; i++) {
- lua_Number d = luaL_checknumber(L, i);
- if (d < dmin)
- dmin = d;
- }
- lua_pushnumber(L, dmin);
- return 1;
+ int n = lua_gettop(L); /* number of arguments */
+ lua_Number dmin = luaL_checknumber(L, 1);
+ int i;
+ for (i=2; i<=n; i++) {
+ lua_Number d = luaL_checknumber(L, i);
+ if (d < dmin)
+ dmin = d;
+ }
+ lua_pushnumber(L, dmin);
+ return 1;
}
static int math_max (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- lua_Number dmax = luaL_checknumber(L, 1);
- int i;
- for (i=2; i<=n; i++) {
- lua_Number d = luaL_checknumber(L, i);
- if (d > dmax)
- dmax = d;
- }
- lua_pushnumber(L, dmax);
- return 1;
+ int n = lua_gettop(L); /* number of arguments */
+ lua_Number dmax = luaL_checknumber(L, 1);
+ int i;
+ for (i=2; i<=n; i++) {
+ lua_Number d = luaL_checknumber(L, i);
+ if (d > dmax)
+ dmax = d;
+ }
+ lua_pushnumber(L, dmax);
+ return 1;
}
static int math_random (lua_State *L) {
- /* the `%' avoids the (rare) case of r==1, and is needed also because on
- some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
- lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
- switch (lua_gettop(L)) { /* check number of arguments */
- case 0: { /* no arguments */
- lua_pushnumber(L, r); /* Number between 0 and 1 */
- break;
- }
- case 1: { /* only upper limit */
- lua_Number u = luaL_checknumber(L, 1);
- luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty");
- lua_pushnumber(L, l_mathop(floor)(r*u) + (lua_Number)(1.0)); /* [1, u] */
- break;
- }
- case 2: { /* lower and upper limits */
- lua_Number l = luaL_checknumber(L, 1);
- lua_Number u = luaL_checknumber(L, 2);
- luaL_argcheck(L, l <= u, 2, "interval is empty");
- lua_pushnumber(L, l_mathop(floor)(r*(u-l+1)) + l); /* [l, u] */
- break;
- }
- default: return luaL_error(L, "wrong number of arguments");
- }
- return 1;
+ /* the `%' avoids the (rare) case of r==1, and is needed also because on
+ some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
+ lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
+ switch (lua_gettop(L)) { /* check number of arguments */
+ case 0: { /* no arguments */
+ lua_pushnumber(L, r); /* Number between 0 and 1 */
+ break;
+ }
+ case 1: { /* only upper limit */
+ lua_Number u = luaL_checknumber(L, 1);
+ luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty");
+ lua_pushnumber(L, l_mathop(floor)(r*u) + (lua_Number)(1.0)); /* [1, u] */
+ break;
+ }
+ case 2: { /* lower and upper limits */
+ lua_Number l = luaL_checknumber(L, 1);
+ lua_Number u = luaL_checknumber(L, 2);
+ luaL_argcheck(L, l <= u, 2, "interval is empty");
+ lua_pushnumber(L, l_mathop(floor)(r*(u-l+1)) + l); /* [l, u] */
+ break;
+ }
+ default: return luaL_error(L, "wrong number of arguments");
+ }
+ return 1;
}
static int math_randomseed (lua_State *L) {
- srand(luaL_checkunsigned(L, 1));
- (void)rand(); /* discard first value to avoid undesirable correlations */
- return 0;
+ srand(luaL_checkunsigned(L, 1));
+ (void)rand(); /* discard first value to avoid undesirable correlations */
+ return 0;
}
static const luaL_Reg mathlib[] = {
- {"abs", math_abs},
- {"acos", math_acos},
- {"asin", math_asin},
- {"atan2", math_atan2},
- {"atan", math_atan},
- {"ceil", math_ceil},
- {"cosh", math_cosh},
- {"cos", math_cos},
- {"deg", math_deg},
- {"exp", math_exp},
- {"floor", math_floor},
- {"fmod", math_fmod},
- {"frexp", math_frexp},
- {"ldexp", math_ldexp},
+ {"abs", math_abs},
+ {"acos", math_acos},
+ {"asin", math_asin},
+ {"atan2", math_atan2},
+ {"atan", math_atan},
+ {"ceil", math_ceil},
+ {"cosh", math_cosh},
+ {"cos", math_cos},
+ {"deg", math_deg},
+ {"exp", math_exp},
+ {"floor", math_floor},
+ {"fmod", math_fmod},
+ {"frexp", math_frexp},
+ {"ldexp", math_ldexp},
#if defined(LUA_COMPAT_LOG10)
- {"log10", math_log10},
+ {"log10", math_log10},
#endif
- {"log", math_log},
- {"max", math_max},
- {"min", math_min},
- {"modf", math_modf},
- {"pow", math_pow},
- {"rad", math_rad},
- {"random", math_random},
- {"randomseed", math_randomseed},
- {"sinh", math_sinh},
- {"sin", math_sin},
- {"sqrt", math_sqrt},
- {"tanh", math_tanh},
- {"tan", math_tan},
- {NULL, NULL}
+ {"log", math_log},
+ {"max", math_max},
+ {"min", math_min},
+ {"modf", math_modf},
+ {"pow", math_pow},
+ {"rad", math_rad},
+ {"random", math_random},
+ {"randomseed", math_randomseed},
+ {"sinh", math_sinh},
+ {"sin", math_sin},
+ {"sqrt", math_sqrt},
+ {"tanh", math_tanh},
+ {"tan", math_tan},
+ {NULL, NULL}
};
@@ -269,11 +269,10 @@ static const luaL_Reg mathlib[] = {
** Open math library
*/
LUAMOD_API int luaopen_math (lua_State *L) {
- luaL_newlib(L, mathlib);
- lua_pushnumber(L, PI);
- lua_setfield(L, -2, "pi");
- lua_pushnumber(L, HUGE_VAL);
- lua_setfield(L, -2, "huge");
- return 1;
+ luaL_newlib(L, mathlib);
+ lua_pushnumber(L, PI);
+ lua_setfield(L, -2, "pi");
+ lua_pushnumber(L, HUGE_VAL);
+ lua_setfield(L, -2, "huge");
+ return 1;
}
-
diff --git a/src/lib/lua/lmem.c b/src/lib/lua/lmem.c
index 3f88496e09d..d7d0266fe0a 100644
--- a/src/lib/lua/lmem.c
+++ b/src/lib/lua/lmem.c
@@ -40,31 +40,31 @@
-#define MINSIZEARRAY 4
+#define MINSIZEARRAY 4
void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
- int limit, const char *what) {
- void *newblock;
- int newsize;
- if (*size >= limit/2) { /* cannot double it? */
- if (*size >= limit) /* cannot grow even a little? */
- luaG_runerror(L, "too many %s (limit is %d)", what, limit);
- newsize = limit; /* still have at least one free place */
- }
- else {
- newsize = (*size)*2;
- if (newsize < MINSIZEARRAY)
- newsize = MINSIZEARRAY; /* minimum size */
- }
- newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
- *size = newsize; /* update only when everything else is OK */
- return newblock;
+ int limit, const char *what) {
+ void *newblock;
+ int newsize;
+ if (*size >= limit/2) { /* cannot double it? */
+ if (*size >= limit) /* cannot grow even a little? */
+ luaG_runerror(L, "too many %s (limit is %d)", what, limit);
+ newsize = limit; /* still have at least one free place */
+ }
+ else {
+ newsize = (*size)*2;
+ if (newsize < MINSIZEARRAY)
+ newsize = MINSIZEARRAY; /* minimum size */
+ }
+ newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
+ *size = newsize; /* update only when everything else is OK */
+ return newblock;
}
l_noret luaM_toobig (lua_State *L) {
- luaG_runerror(L, "memory allocation error: block too big");
+ luaG_runerror(L, "memory allocation error: block too big");
}
@@ -73,27 +73,26 @@ l_noret luaM_toobig (lua_State *L) {
** generic allocation routine.
*/
void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
- void *newblock;
- global_State *g = G(L);
- size_t realosize = (block) ? osize : 0;
- lua_assert((realosize == 0) == (block == NULL));
+ void *newblock;
+ global_State *g = G(L);
+ size_t realosize = (block) ? osize : 0;
+ lua_assert((realosize == 0) == (block == NULL));
#if defined(HARDMEMTESTS)
- if (nsize > realosize && g->gcrunning)
- luaC_fullgc(L, 1); /* force a GC whenever possible */
+ if (nsize > realosize && g->gcrunning)
+ luaC_fullgc(L, 1); /* force a GC whenever possible */
#endif
- newblock = (*g->frealloc)(g->ud, block, osize, nsize);
- if (newblock == NULL && nsize > 0) {
- api_check(L, nsize > realosize,
- "realloc cannot fail when shrinking a block");
- if (g->gcrunning) {
- luaC_fullgc(L, 1); /* try to free some memory... */
- newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
- }
- if (newblock == NULL)
- luaD_throw(L, LUA_ERRMEM);
- }
- lua_assert((nsize == 0) == (newblock == NULL));
- g->GCdebt = (g->GCdebt + nsize) - realosize;
- return newblock;
+ newblock = (*g->frealloc)(g->ud, block, osize, nsize);
+ if (newblock == NULL && nsize > 0) {
+ api_check(L, nsize > realosize,
+ "realloc cannot fail when shrinking a block");
+ if (g->gcrunning) {
+ luaC_fullgc(L, 1); /* try to free some memory... */
+ newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
+ }
+ if (newblock == NULL)
+ luaD_throw(L, LUA_ERRMEM);
+ }
+ lua_assert((nsize == 0) == (newblock == NULL));
+ g->GCdebt = (g->GCdebt + nsize) - realosize;
+ return newblock;
}
-
diff --git a/src/lib/lua/lmem.h b/src/lib/lua/lmem.h
index 5f850999a9d..48e309221c0 100644
--- a/src/lib/lua/lmem.h
+++ b/src/lib/lua/lmem.h
@@ -22,36 +22,35 @@
** cast to 'void' avoids warnings of "value unused".
*/
#define luaM_reallocv(L,b,on,n,e) \
- (cast(void, \
- (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
- luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
+ (cast(void, \
+ (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
+ luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
-#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
-#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
+#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
+#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
#define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))
-#define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s))
-#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
+#define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s))
+#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
#define luaM_newvector(L,n,t) \
cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
-#define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s))
+#define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s))
#define luaM_growvector(L,v,nelems,size,t,limit,e) \
- if ((nelems)+1 > (size)) \
- ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
+ if ((nelems)+1 > (size)) \
+ ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
#define luaM_reallocvector(L, v,oldn,n,t) \
- ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
+ ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
LUAI_FUNC l_noret luaM_toobig (lua_State *L);
/* not to be called directly */
LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
- size_t size);
+ size_t size);
LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
- size_t size_elem, int limit,
- const char *what);
+ size_t size_elem, int limit,
+ const char *what);
#endif
-
diff --git a/src/lib/lua/loadlib.c b/src/lib/lua/loadlib.c
index a9959277bd8..3b60a9e5791 100644
--- a/src/lib/lua/loadlib.c
+++ b/src/lib/lua/loadlib.c
@@ -35,17 +35,17 @@
** variables that Lua check to set its paths.
*/
#if !defined(LUA_PATH)
-#define LUA_PATH "LUA_PATH"
+#define LUA_PATH "LUA_PATH"
#endif
#if !defined(LUA_CPATH)
-#define LUA_CPATH "LUA_CPATH"
+#define LUA_CPATH "LUA_CPATH"
#endif
-#define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
+#define LUA_PATHSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
-#define LUA_PATHVERSION LUA_PATH LUA_PATHSUFFIX
-#define LUA_CPATHVERSION LUA_CPATH LUA_PATHSUFFIX
+#define LUA_PATHVERSION LUA_PATH LUA_PATHSUFFIX
+#define LUA_CPATHVERSION LUA_CPATH LUA_PATHSUFFIX
/*
** LUA_PATH_SEP is the character that separates templates in a path.
@@ -57,16 +57,16 @@
** luaopen_ function name.
*/
#if !defined (LUA_PATH_SEP)
-#define LUA_PATH_SEP ";"
+#define LUA_PATH_SEP ";"
#endif
#if !defined (LUA_PATH_MARK)
-#define LUA_PATH_MARK "?"
+#define LUA_PATH_MARK "?"
#endif
#if !defined (LUA_EXEC_DIR)
-#define LUA_EXEC_DIR "!"
+#define LUA_EXEC_DIR "!"
#endif
#if !defined (LUA_IGMARK)
-#define LUA_IGMARK "-"
+#define LUA_IGMARK "-"
#endif
@@ -77,32 +77,32 @@
** when searching for a Lua loader.
*/
#if !defined(LUA_CSUBSEP)
-#define LUA_CSUBSEP LUA_DIRSEP
+#define LUA_CSUBSEP LUA_DIRSEP
#endif
#if !defined(LUA_LSUBSEP)
-#define LUA_LSUBSEP LUA_DIRSEP
+#define LUA_LSUBSEP LUA_DIRSEP
#endif
/* prefix for open functions in C libraries */
-#define LUA_POF "luaopen_"
+#define LUA_POF "luaopen_"
/* separator for open functions in C libraries */
-#define LUA_OFSEP "_"
+#define LUA_OFSEP "_"
/* table (in the registry) that keeps handles for all loaded C libraries */
-#define CLIBS "_CLIBS"
+#define CLIBS "_CLIBS"
-#define LIB_FAIL "open"
+#define LIB_FAIL "open"
/* error codes for ll_loadfunc */
-#define ERRLIB 1
-#define ERRFUNC 2
+#define ERRLIB 1
+#define ERRFUNC 2
-#define setprogdir(L) ((void)0)
+#define setprogdir(L) ((void)0)
/*
@@ -127,21 +127,21 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
#include <dlfcn.h>
static void ll_unloadlib (void *lib) {
- dlclose(lib);
+ dlclose(lib);
}
static void *ll_load (lua_State *L, const char *path, int seeglb) {
- void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));
- if (lib == NULL) lua_pushstring(L, dlerror());
- return lib;
+ void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));
+ if (lib == NULL) lua_pushstring(L, dlerror());
+ return lib;
}
static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
- if (f == NULL) lua_pushstring(L, dlerror());
- return f;
+ lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
+ if (f == NULL) lua_pushstring(L, dlerror());
+ return f;
}
/* }====================================================== */
@@ -161,52 +161,52 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
** optional flags for LoadLibraryEx
*/
#if !defined(LUA_LLE_FLAGS)
-#define LUA_LLE_FLAGS 0
+#define LUA_LLE_FLAGS 0
#endif
static void setprogdir (lua_State *L) {
- char buff[MAX_PATH + 1];
- char *lb;
- DWORD nsize = sizeof(buff)/sizeof(char);
- DWORD n = GetModuleFileNameA(NULL, buff, nsize);
- if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
- luaL_error(L, "unable to get ModuleFileName");
- else {
- *lb = '\0';
- luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
- lua_remove(L, -2); /* remove original string */
- }
+ char buff[MAX_PATH + 1];
+ char *lb;
+ DWORD nsize = sizeof(buff)/sizeof(char);
+ DWORD n = GetModuleFileNameA(NULL, buff, nsize);
+ if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
+ luaL_error(L, "unable to get ModuleFileName");
+ else {
+ *lb = '\0';
+ luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
+ lua_remove(L, -2); /* remove original string */
+ }
}
static void pusherror (lua_State *L) {
- int error = GetLastError();
- char buffer[128];
- if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))
- lua_pushstring(L, buffer);
- else
- lua_pushfstring(L, "system error %d\n", error);
+ int error = GetLastError();
+ char buffer[128];
+ if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))
+ lua_pushstring(L, buffer);
+ else
+ lua_pushfstring(L, "system error %d\n", error);
}
static void ll_unloadlib (void *lib) {
- FreeLibrary((HMODULE)lib);
+ FreeLibrary((HMODULE)lib);
}
static void *ll_load (lua_State *L, const char *path, int seeglb) {
- HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
- (void)(seeglb); /* not used: symbols are 'global' by default */
- if (lib == NULL) pusherror(L);
- return lib;
+ HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
+ (void)(seeglb); /* not used: symbols are 'global' by default */
+ if (lib == NULL) pusherror(L);
+ return lib;
}
static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);
- if (f == NULL) pusherror(L);
- return f;
+ lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);
+ if (f == NULL) pusherror(L);
+ return f;
}
/* }====================================================== */
@@ -220,28 +220,28 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
*/
#undef LIB_FAIL
-#define LIB_FAIL "absent"
+#define LIB_FAIL "absent"
-#define DLMSG "dynamic libraries not enabled; check your Lua installation"
+#define DLMSG "dynamic libraries not enabled; check your Lua installation"
static void ll_unloadlib (void *lib) {
- (void)(lib); /* not used */
+ (void)(lib); /* not used */
}
static void *ll_load (lua_State *L, const char *path, int seeglb) {
- (void)(path); (void)(seeglb); /* not used */
- lua_pushliteral(L, DLMSG);
- return NULL;
+ (void)(path); (void)(seeglb); /* not used */
+ lua_pushliteral(L, DLMSG);
+ return NULL;
}
static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- (void)(lib); (void)(sym); /* not used */
- lua_pushliteral(L, DLMSG);
- return NULL;
+ (void)(lib); (void)(sym); /* not used */
+ lua_pushliteral(L, DLMSG);
+ return NULL;
}
/* }====================================================== */
@@ -249,22 +249,22 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
static void *ll_checkclib (lua_State *L, const char *path) {
- void *plib;
- lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
- lua_getfield(L, -1, path);
- plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */
- lua_pop(L, 2); /* pop CLIBS table and 'plib' */
- return plib;
+ void *plib;
+ lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
+ lua_getfield(L, -1, path);
+ plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */
+ lua_pop(L, 2); /* pop CLIBS table and 'plib' */
+ return plib;
}
static void ll_addtoclib (lua_State *L, const char *path, void *plib) {
- lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
- lua_pushlightuserdata(L, plib);
- lua_pushvalue(L, -1);
- lua_setfield(L, -3, path); /* CLIBS[path] = plib */
- lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
- lua_pop(L, 1); /* pop CLIBS table */
+ lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
+ lua_pushlightuserdata(L, plib);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -3, path); /* CLIBS[path] = plib */
+ lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
+ lua_pop(L, 1); /* pop CLIBS table */
}
@@ -273,49 +273,49 @@ static void ll_addtoclib (lua_State *L, const char *path, void *plib) {
** handles in list CLIBS
*/
static int gctm (lua_State *L) {
- int n = luaL_len(L, 1);
- for (; n >= 1; n--) { /* for each handle, in reverse order */
- lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */
- ll_unloadlib(lua_touserdata(L, -1));
- lua_pop(L, 1); /* pop handle */
- }
- return 0;
+ int n = luaL_len(L, 1);
+ for (; n >= 1; n--) { /* for each handle, in reverse order */
+ lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */
+ ll_unloadlib(lua_touserdata(L, -1));
+ lua_pop(L, 1); /* pop handle */
+ }
+ return 0;
}
static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
- void *reg = ll_checkclib(L, path); /* check loaded C libraries */
- if (reg == NULL) { /* must load library? */
- reg = ll_load(L, path, *sym == '*');
- if (reg == NULL) return ERRLIB; /* unable to load library */
- ll_addtoclib(L, path, reg);
- }
- if (*sym == '*') { /* loading only library (no function)? */
- lua_pushboolean(L, 1); /* return 'true' */
- return 0; /* no errors */
- }
- else {
- lua_CFunction f = ll_sym(L, reg, sym);
- if (f == NULL)
- return ERRFUNC; /* unable to find function */
- lua_pushcfunction(L, f); /* else create new function */
- return 0; /* no errors */
- }
+ void *reg = ll_checkclib(L, path); /* check loaded C libraries */
+ if (reg == NULL) { /* must load library? */
+ reg = ll_load(L, path, *sym == '*');
+ if (reg == NULL) return ERRLIB; /* unable to load library */
+ ll_addtoclib(L, path, reg);
+ }
+ if (*sym == '*') { /* loading only library (no function)? */
+ lua_pushboolean(L, 1); /* return 'true' */
+ return 0; /* no errors */
+ }
+ else {
+ lua_CFunction f = ll_sym(L, reg, sym);
+ if (f == NULL)
+ return ERRFUNC; /* unable to find function */
+ lua_pushcfunction(L, f); /* else create new function */
+ return 0; /* no errors */
+ }
}
static int ll_loadlib (lua_State *L) {
- const char *path = luaL_checkstring(L, 1);
- const char *init = luaL_checkstring(L, 2);
- int stat = ll_loadfunc(L, path, init);
- if (stat == 0) /* no errors? */
- return 1; /* return the loaded function */
- else { /* error; error message is on stack top */
- lua_pushnil(L);
- lua_insert(L, -2);
- lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init");
- return 3; /* return nil, error message, and where */
- }
+ const char *path = luaL_checkstring(L, 1);
+ const char *init = luaL_checkstring(L, 2);
+ int stat = ll_loadfunc(L, path, init);
+ if (stat == 0) /* no errors? */
+ return 1; /* return the loaded function */
+ else { /* error; error message is on stack top */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init");
+ return 3; /* return nil, error message, and where */
+ }
}
@@ -328,205 +328,205 @@ static int ll_loadlib (lua_State *L) {
static int readable (const char *filename) {
- FILE *f = fopen(filename, "r"); /* try to open file */
- if (f == NULL) return 0; /* open failed */
- fclose(f);
- return 1;
+ FILE *f = fopen(filename, "r"); /* try to open file */
+ if (f == NULL) return 0; /* open failed */
+ fclose(f);
+ return 1;
}
static const char *pushnexttemplate (lua_State *L, const char *path) {
- const char *l;
- while (*path == *LUA_PATH_SEP) path++; /* skip separators */
- if (*path == '\0') return NULL; /* no more templates */
- l = strchr(path, *LUA_PATH_SEP); /* find next separator */
- if (l == NULL) l = path + strlen(path);
- lua_pushlstring(L, path, l - path); /* template */
- return l;
+ const char *l;
+ while (*path == *LUA_PATH_SEP) path++; /* skip separators */
+ if (*path == '\0') return NULL; /* no more templates */
+ l = strchr(path, *LUA_PATH_SEP); /* find next separator */
+ if (l == NULL) l = path + strlen(path);
+ lua_pushlstring(L, path, l - path); /* template */
+ return l;
}
static const char *searchpath (lua_State *L, const char *name,
- const char *path,
- const char *sep,
- const char *dirsep) {
- luaL_Buffer msg; /* to build error message */
- luaL_buffinit(L, &msg);
- if (*sep != '\0') /* non-empty separator? */
- name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
- while ((path = pushnexttemplate(L, path)) != NULL) {
- const char *filename = luaL_gsub(L, lua_tostring(L, -1),
- LUA_PATH_MARK, name);
- lua_remove(L, -2); /* remove path template */
- if (readable(filename)) /* does file exist and is readable? */
- return filename; /* return that file name */
- lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
- lua_remove(L, -2); /* remove file name */
- luaL_addvalue(&msg); /* concatenate error msg. entry */
- }
- luaL_pushresult(&msg); /* create error message */
- return NULL; /* not found */
+ const char *path,
+ const char *sep,
+ const char *dirsep) {
+ luaL_Buffer msg; /* to build error message */
+ luaL_buffinit(L, &msg);
+ if (*sep != '\0') /* non-empty separator? */
+ name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
+ while ((path = pushnexttemplate(L, path)) != NULL) {
+ const char *filename = luaL_gsub(L, lua_tostring(L, -1),
+ LUA_PATH_MARK, name);
+ lua_remove(L, -2); /* remove path template */
+ if (readable(filename)) /* does file exist and is readable? */
+ return filename; /* return that file name */
+ lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
+ lua_remove(L, -2); /* remove file name */
+ luaL_addvalue(&msg); /* concatenate error msg. entry */
+ }
+ luaL_pushresult(&msg); /* create error message */
+ return NULL; /* not found */
}
static int ll_searchpath (lua_State *L) {
- const char *f = searchpath(L, luaL_checkstring(L, 1),
- luaL_checkstring(L, 2),
- luaL_optstring(L, 3, "."),
- luaL_optstring(L, 4, LUA_DIRSEP));
- if (f != NULL) return 1;
- else { /* error message is on top of the stack */
- lua_pushnil(L);
- lua_insert(L, -2);
- return 2; /* return nil + error message */
- }
+ const char *f = searchpath(L, luaL_checkstring(L, 1),
+ luaL_checkstring(L, 2),
+ luaL_optstring(L, 3, "."),
+ luaL_optstring(L, 4, LUA_DIRSEP));
+ if (f != NULL) return 1;
+ else { /* error message is on top of the stack */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ return 2; /* return nil + error message */
+ }
}
static const char *findfile (lua_State *L, const char *name,
- const char *pname,
- const char *dirsep) {
- const char *path;
- lua_getfield(L, lua_upvalueindex(1), pname);
- path = lua_tostring(L, -1);
- if (path == NULL)
- luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
- return searchpath(L, name, path, ".", dirsep);
+ const char *pname,
+ const char *dirsep) {
+ const char *path;
+ lua_getfield(L, lua_upvalueindex(1), pname);
+ path = lua_tostring(L, -1);
+ if (path == NULL)
+ luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
+ return searchpath(L, name, path, ".", dirsep);
}
static int checkload (lua_State *L, int stat, const char *filename) {
- if (stat) { /* module loaded successfully? */
- lua_pushstring(L, filename); /* will be 2nd argument to module */
- return 2; /* return open function and file name */
- }
- else
- return luaL_error(L, "error loading module " LUA_QS
- " from file " LUA_QS ":\n\t%s",
- lua_tostring(L, 1), filename, lua_tostring(L, -1));
+ if (stat) { /* module loaded successfully? */
+ lua_pushstring(L, filename); /* will be 2nd argument to module */
+ return 2; /* return open function and file name */
+ }
+ else
+ return luaL_error(L, "error loading module " LUA_QS
+ " from file " LUA_QS ":\n\t%s",
+ lua_tostring(L, 1), filename, lua_tostring(L, -1));
}
static int searcher_Lua (lua_State *L) {
- const char *filename;
- const char *name = luaL_checkstring(L, 1);
- filename = findfile(L, name, "path", LUA_LSUBSEP);
- if (filename == NULL) return 1; /* module not found in this path */
- return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);
+ const char *filename;
+ const char *name = luaL_checkstring(L, 1);
+ filename = findfile(L, name, "path", LUA_LSUBSEP);
+ if (filename == NULL) return 1; /* module not found in this path */
+ return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);
}
static int loadfunc (lua_State *L, const char *filename, const char *modname) {
- const char *funcname;
- const char *mark;
- modname = luaL_gsub(L, modname, ".", LUA_OFSEP);
- mark = strchr(modname, *LUA_IGMARK);
- if (mark) {
- int stat;
- funcname = lua_pushlstring(L, modname, mark - modname);
- funcname = lua_pushfstring(L, LUA_POF"%s", funcname);
- stat = ll_loadfunc(L, filename, funcname);
- if (stat != ERRFUNC) return stat;
- modname = mark + 1; /* else go ahead and try old-style name */
- }
- funcname = lua_pushfstring(L, LUA_POF"%s", modname);
- return ll_loadfunc(L, filename, funcname);
+ const char *funcname;
+ const char *mark;
+ modname = luaL_gsub(L, modname, ".", LUA_OFSEP);
+ mark = strchr(modname, *LUA_IGMARK);
+ if (mark) {
+ int stat;
+ funcname = lua_pushlstring(L, modname, mark - modname);
+ funcname = lua_pushfstring(L, LUA_POF"%s", funcname);
+ stat = ll_loadfunc(L, filename, funcname);
+ if (stat != ERRFUNC) return stat;
+ modname = mark + 1; /* else go ahead and try old-style name */
+ }
+ funcname = lua_pushfstring(L, LUA_POF"%s", modname);
+ return ll_loadfunc(L, filename, funcname);
}
static int searcher_C (lua_State *L) {
- const char *name = luaL_checkstring(L, 1);
- const char *filename = findfile(L, name, "cpath", LUA_CSUBSEP);
- if (filename == NULL) return 1; /* module not found in this path */
- return checkload(L, (loadfunc(L, filename, name) == 0), filename);
+ const char *name = luaL_checkstring(L, 1);
+ const char *filename = findfile(L, name, "cpath", LUA_CSUBSEP);
+ if (filename == NULL) return 1; /* module not found in this path */
+ return checkload(L, (loadfunc(L, filename, name) == 0), filename);
}
static int searcher_Croot (lua_State *L) {
- const char *filename;
- const char *name = luaL_checkstring(L, 1);
- const char *p = strchr(name, '.');
- int stat;
- if (p == NULL) return 0; /* is root */
- lua_pushlstring(L, name, p - name);
- filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP);
- if (filename == NULL) return 1; /* root not found */
- if ((stat = loadfunc(L, filename, name)) != 0) {
- if (stat != ERRFUNC)
- return checkload(L, 0, filename); /* real error */
- else { /* open function not found */
- lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
- name, filename);
- return 1;
- }
- }
- lua_pushstring(L, filename); /* will be 2nd argument to module */
- return 2;
+ const char *filename;
+ const char *name = luaL_checkstring(L, 1);
+ const char *p = strchr(name, '.');
+ int stat;
+ if (p == NULL) return 0; /* is root */
+ lua_pushlstring(L, name, p - name);
+ filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP);
+ if (filename == NULL) return 1; /* root not found */
+ if ((stat = loadfunc(L, filename, name)) != 0) {
+ if (stat != ERRFUNC)
+ return checkload(L, 0, filename); /* real error */
+ else { /* open function not found */
+ lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
+ name, filename);
+ return 1;
+ }
+ }
+ lua_pushstring(L, filename); /* will be 2nd argument to module */
+ return 2;
}
static int searcher_preload (lua_State *L) {
- const char *name = luaL_checkstring(L, 1);
- lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
- lua_getfield(L, -1, name);
- if (lua_isnil(L, -1)) /* not found? */
- lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
- return 1;
+ const char *name = luaL_checkstring(L, 1);
+ lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
+ lua_getfield(L, -1, name);
+ if (lua_isnil(L, -1)) /* not found? */
+ lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
+ return 1;
}
static void findloader (lua_State *L, const char *name) {
- int i;
- luaL_Buffer msg; /* to build error message */
- luaL_buffinit(L, &msg);
- lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */
- if (!lua_istable(L, 3))
- luaL_error(L, LUA_QL("package.searchers") " must be a table");
- /* iterate over available searchers to find a loader */
- for (i = 1; ; i++) {
- lua_rawgeti(L, 3, i); /* get a searcher */
- if (lua_isnil(L, -1)) { /* no more searchers? */
- lua_pop(L, 1); /* remove nil */
- luaL_pushresult(&msg); /* create error message */
- luaL_error(L, "module " LUA_QS " not found:%s",
- name, lua_tostring(L, -1));
- }
- lua_pushstring(L, name);
- lua_call(L, 1, 2); /* call it */
- if (lua_isfunction(L, -2)) /* did it find a loader? */
- return; /* module loader found */
- else if (lua_isstring(L, -2)) { /* searcher returned error message? */
- lua_pop(L, 1); /* remove extra return */
- luaL_addvalue(&msg); /* concatenate error message */
- }
- else
- lua_pop(L, 2); /* remove both returns */
- }
+ int i;
+ luaL_Buffer msg; /* to build error message */
+ luaL_buffinit(L, &msg);
+ lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */
+ if (!lua_istable(L, 3))
+ luaL_error(L, LUA_QL("package.searchers") " must be a table");
+ /* iterate over available searchers to find a loader */
+ for (i = 1; ; i++) {
+ lua_rawgeti(L, 3, i); /* get a searcher */
+ if (lua_isnil(L, -1)) { /* no more searchers? */
+ lua_pop(L, 1); /* remove nil */
+ luaL_pushresult(&msg); /* create error message */
+ luaL_error(L, "module " LUA_QS " not found:%s",
+ name, lua_tostring(L, -1));
+ }
+ lua_pushstring(L, name);
+ lua_call(L, 1, 2); /* call it */
+ if (lua_isfunction(L, -2)) /* did it find a loader? */
+ return; /* module loader found */
+ else if (lua_isstring(L, -2)) { /* searcher returned error message? */
+ lua_pop(L, 1); /* remove extra return */
+ luaL_addvalue(&msg); /* concatenate error message */
+ }
+ else
+ lua_pop(L, 2); /* remove both returns */
+ }
}
static int ll_require (lua_State *L) {
- const char *name = luaL_checkstring(L, 1);
- lua_settop(L, 1); /* _LOADED table will be at index 2 */
- lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_getfield(L, 2, name); /* _LOADED[name] */
- if (lua_toboolean(L, -1)) /* is it there? */
- return 1; /* package is already loaded */
- /* else must load package */
- lua_pop(L, 1); /* remove 'getfield' result */
- findloader(L, name);
- lua_pushstring(L, name); /* pass name as argument to module loader */
- lua_insert(L, -2); /* name is 1st argument (before search data) */
- lua_call(L, 2, 1); /* run loader to load module */
- if (!lua_isnil(L, -1)) /* non-nil return? */
- lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
- lua_getfield(L, 2, name);
- if (lua_isnil(L, -1)) { /* module did not set a value? */
- lua_pushboolean(L, 1); /* use true as result */
- lua_pushvalue(L, -1); /* extra copy to be returned */
- lua_setfield(L, 2, name); /* _LOADED[name] = true */
- }
- return 1;
+ const char *name = luaL_checkstring(L, 1);
+ lua_settop(L, 1); /* _LOADED table will be at index 2 */
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, 2, name); /* _LOADED[name] */
+ if (lua_toboolean(L, -1)) /* is it there? */
+ return 1; /* package is already loaded */
+ /* else must load package */
+ lua_pop(L, 1); /* remove 'getfield' result */
+ findloader(L, name);
+ lua_pushstring(L, name); /* pass name as argument to module loader */
+ lua_insert(L, -2); /* name is 1st argument (before search data) */
+ lua_call(L, 2, 1); /* run loader to load module */
+ if (!lua_isnil(L, -1)) /* non-nil return? */
+ lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
+ lua_getfield(L, 2, name);
+ if (lua_isnil(L, -1)) { /* module did not set a value? */
+ lua_pushboolean(L, 1); /* use true as result */
+ lua_pushvalue(L, -1); /* extra copy to be returned */
+ lua_setfield(L, 2, name); /* _LOADED[name] = true */
+ }
+ return 1;
}
/* }====================================================== */
@@ -544,73 +544,73 @@ static int ll_require (lua_State *L) {
** changes the environment variable of calling function
*/
static void set_env (lua_State *L) {
- lua_Debug ar;
- if (lua_getstack(L, 1, &ar) == 0 ||
- lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
- lua_iscfunction(L, -1))
- luaL_error(L, LUA_QL("module") " not called from a Lua function");
- lua_pushvalue(L, -2); /* copy new environment table to top */
- lua_setupvalue(L, -2, 1);
- lua_pop(L, 1); /* remove function */
+ lua_Debug ar;
+ if (lua_getstack(L, 1, &ar) == 0 ||
+ lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
+ lua_iscfunction(L, -1))
+ luaL_error(L, LUA_QL("module") " not called from a Lua function");
+ lua_pushvalue(L, -2); /* copy new environment table to top */
+ lua_setupvalue(L, -2, 1);
+ lua_pop(L, 1); /* remove function */
}
static void dooptions (lua_State *L, int n) {
- int i;
- for (i = 2; i <= n; i++) {
- if (lua_isfunction(L, i)) { /* avoid 'calling' extra info. */
- lua_pushvalue(L, i); /* get option (a function) */
- lua_pushvalue(L, -2); /* module */
- lua_call(L, 1, 0);
- }
- }
+ int i;
+ for (i = 2; i <= n; i++) {
+ if (lua_isfunction(L, i)) { /* avoid 'calling' extra info. */
+ lua_pushvalue(L, i); /* get option (a function) */
+ lua_pushvalue(L, -2); /* module */
+ lua_call(L, 1, 0);
+ }
+ }
}
static void modinit (lua_State *L, const char *modname) {
- const char *dot;
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "_M"); /* module._M = module */
- lua_pushstring(L, modname);
- lua_setfield(L, -2, "_NAME");
- dot = strrchr(modname, '.'); /* look for last dot in module name */
- if (dot == NULL) dot = modname;
- else dot++;
- /* set _PACKAGE as package name (full module name minus last part) */
- lua_pushlstring(L, modname, dot - modname);
- lua_setfield(L, -2, "_PACKAGE");
+ const char *dot;
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "_M"); /* module._M = module */
+ lua_pushstring(L, modname);
+ lua_setfield(L, -2, "_NAME");
+ dot = strrchr(modname, '.'); /* look for last dot in module name */
+ if (dot == NULL) dot = modname;
+ else dot++;
+ /* set _PACKAGE as package name (full module name minus last part) */
+ lua_pushlstring(L, modname, dot - modname);
+ lua_setfield(L, -2, "_PACKAGE");
}
static int ll_module (lua_State *L) {
- const char *modname = luaL_checkstring(L, 1);
- int lastarg = lua_gettop(L); /* last parameter */
- luaL_pushmodule(L, modname, 1); /* get/create module table */
- /* check whether table already has a _NAME field */
- lua_getfield(L, -1, "_NAME");
- if (!lua_isnil(L, -1)) /* is table an initialized module? */
- lua_pop(L, 1);
- else { /* no; initialize it */
- lua_pop(L, 1);
- modinit(L, modname);
- }
- lua_pushvalue(L, -1);
- set_env(L);
- dooptions(L, lastarg);
- return 1;
+ const char *modname = luaL_checkstring(L, 1);
+ int lastarg = lua_gettop(L); /* last parameter */
+ luaL_pushmodule(L, modname, 1); /* get/create module table */
+ /* check whether table already has a _NAME field */
+ lua_getfield(L, -1, "_NAME");
+ if (!lua_isnil(L, -1)) /* is table an initialized module? */
+ lua_pop(L, 1);
+ else { /* no; initialize it */
+ lua_pop(L, 1);
+ modinit(L, modname);
+ }
+ lua_pushvalue(L, -1);
+ set_env(L);
+ dooptions(L, lastarg);
+ return 1;
}
static int ll_seeall (lua_State *L) {
- luaL_checktype(L, 1, LUA_TTABLE);
- if (!lua_getmetatable(L, 1)) {
- lua_createtable(L, 0, 1); /* create new metatable */
- lua_pushvalue(L, -1);
- lua_setmetatable(L, 1);
- }
- lua_pushglobaltable(L);
- lua_setfield(L, -2, "__index"); /* mt.__index = _G */
- return 0;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ if (!lua_getmetatable(L, 1)) {
+ lua_createtable(L, 0, 1); /* create new metatable */
+ lua_pushvalue(L, -1);
+ lua_setmetatable(L, 1);
+ }
+ lua_pushglobaltable(L);
+ lua_setfield(L, -2, "__index"); /* mt.__index = _G */
+ return 0;
}
#endif
@@ -619,107 +619,106 @@ static int ll_seeall (lua_State *L) {
/* auxiliary mark (for internal use) */
-#define AUXMARK "\1"
+#define AUXMARK "\1"
/*
** return registry.LUA_NOENV as a boolean
*/
static int noenv (lua_State *L) {
- int b;
- lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
- b = lua_toboolean(L, -1);
- lua_pop(L, 1); /* remove value */
- return b;
+ int b;
+ lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ b = lua_toboolean(L, -1);
+ lua_pop(L, 1); /* remove value */
+ return b;
}
static void setpath (lua_State *L, const char *fieldname, const char *envname1,
- const char *envname2, const char *def) {
- const char *path = getenv(envname1);
- if (path == NULL) /* no environment variable? */
- path = getenv(envname2); /* try alternative name */
- if (path == NULL || noenv(L)) /* no environment variable? */
- lua_pushstring(L, def); /* use default */
- else {
- /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
- path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
- LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
- luaL_gsub(L, path, AUXMARK, def);
- lua_remove(L, -2);
- }
- setprogdir(L);
- lua_setfield(L, -2, fieldname);
+ const char *envname2, const char *def) {
+ const char *path = getenv(envname1);
+ if (path == NULL) /* no environment variable? */
+ path = getenv(envname2); /* try alternative name */
+ if (path == NULL || noenv(L)) /* no environment variable? */
+ lua_pushstring(L, def); /* use default */
+ else {
+ /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
+ path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
+ LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
+ luaL_gsub(L, path, AUXMARK, def);
+ lua_remove(L, -2);
+ }
+ setprogdir(L);
+ lua_setfield(L, -2, fieldname);
}
static const luaL_Reg pk_funcs[] = {
- {"loadlib", ll_loadlib},
- {"searchpath", ll_searchpath},
+ {"loadlib", ll_loadlib},
+ {"searchpath", ll_searchpath},
#if defined(LUA_COMPAT_MODULE)
- {"seeall", ll_seeall},
+ {"seeall", ll_seeall},
#endif
- {NULL, NULL}
+ {NULL, NULL}
};
static const luaL_Reg ll_funcs[] = {
#if defined(LUA_COMPAT_MODULE)
- {"module", ll_module},
+ {"module", ll_module},
#endif
- {"require", ll_require},
- {NULL, NULL}
+ {"require", ll_require},
+ {NULL, NULL}
};
static void createsearcherstable (lua_State *L) {
- static const lua_CFunction searchers[] =
- {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
- int i;
- /* create 'searchers' table */
- lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
- /* fill it with pre-defined searchers */
- for (i=0; searchers[i] != NULL; i++) {
- lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */
- lua_pushcclosure(L, searchers[i], 1);
- lua_rawseti(L, -2, i+1);
- }
+ static const lua_CFunction searchers[] =
+ {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
+ int i;
+ /* create 'searchers' table */
+ lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
+ /* fill it with pre-defined searchers */
+ for (i=0; searchers[i] != NULL; i++) {
+ lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */
+ lua_pushcclosure(L, searchers[i], 1);
+ lua_rawseti(L, -2, i+1);
+ }
}
LUAMOD_API int luaopen_package (lua_State *L) {
- /* create table CLIBS to keep track of loaded C libraries */
- luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
- lua_createtable(L, 0, 1); /* metatable for CLIBS */
- lua_pushcfunction(L, gctm);
- lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */
- lua_setmetatable(L, -2);
- /* create `package' table */
- luaL_newlib(L, pk_funcs);
- createsearcherstable(L);
+ /* create table CLIBS to keep track of loaded C libraries */
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
+ lua_createtable(L, 0, 1); /* metatable for CLIBS */
+ lua_pushcfunction(L, gctm);
+ lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */
+ lua_setmetatable(L, -2);
+ /* create `package' table */
+ luaL_newlib(L, pk_funcs);
+ createsearcherstable(L);
#if defined(LUA_COMPAT_LOADERS)
- lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
- lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */
+ lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
+ lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */
#endif
- lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
- /* set field 'path' */
- setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT);
- /* set field 'cpath' */
- setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT);
- /* store config information */
- lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
- LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
- lua_setfield(L, -2, "config");
- /* set field `loaded' */
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_setfield(L, -2, "loaded");
- /* set field `preload' */
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
- lua_setfield(L, -2, "preload");
- lua_pushglobaltable(L);
- lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */
- luaL_setfuncs(L, ll_funcs, 1); /* open lib into global table */
- lua_pop(L, 1); /* pop global table */
- return 1; /* return 'package' table */
+ lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
+ /* set field 'path' */
+ setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT);
+ /* set field 'cpath' */
+ setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT);
+ /* store config information */
+ lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
+ LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
+ lua_setfield(L, -2, "config");
+ /* set field `loaded' */
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_setfield(L, -2, "loaded");
+ /* set field `preload' */
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
+ lua_setfield(L, -2, "preload");
+ lua_pushglobaltable(L);
+ lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */
+ luaL_setfuncs(L, ll_funcs, 1); /* open lib into global table */
+ lua_pop(L, 1); /* pop global table */
+ return 1; /* return 'package' table */
}
-
diff --git a/src/lib/lua/lobject.c b/src/lib/lua/lobject.c
index 18b4096c8d1..02e7b9de207 100644
--- a/src/lib/lua/lobject.c
+++ b/src/lib/lua/lobject.c
@@ -34,59 +34,59 @@ LUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT};
** eeeee != 0 and (xxx) otherwise.
*/
int luaO_int2fb (unsigned int x) {
- int e = 0; /* exponent */
- if (x < 8) return x;
- while (x >= 0x10) {
- x = (x+1) >> 1;
- e++;
- }
- return ((e+1) << 3) | (cast_int(x) - 8);
+ int e = 0; /* exponent */
+ if (x < 8) return x;
+ while (x >= 0x10) {
+ x = (x+1) >> 1;
+ e++;
+ }
+ return ((e+1) << 3) | (cast_int(x) - 8);
}
/* converts back */
int luaO_fb2int (int x) {
- int e = (x >> 3) & 0x1f;
- if (e == 0) return x;
- else return ((x & 7) + 8) << (e - 1);
+ int e = (x >> 3) & 0x1f;
+ if (e == 0) return x;
+ else return ((x & 7) + 8) << (e - 1);
}
int luaO_ceillog2 (unsigned int x) {
- static const lu_byte log_2[256] = {
- 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
- };
- int l = 0;
- x--;
- while (x >= 256) { l += 8; x >>= 8; }
- return l + log_2[x];
+ static const lu_byte log_2[256] = {
+ 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
+ };
+ int l = 0;
+ x--;
+ while (x >= 256) { l += 8; x >>= 8; }
+ return l + log_2[x];
}
lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) {
- switch (op) {
- case LUA_OPADD: return luai_numadd(NULL, v1, v2);
- case LUA_OPSUB: return luai_numsub(NULL, v1, v2);
- case LUA_OPMUL: return luai_nummul(NULL, v1, v2);
- case LUA_OPDIV: return luai_numdiv(NULL, v1, v2);
- case LUA_OPMOD: return luai_nummod(NULL, v1, v2);
- case LUA_OPPOW: return luai_numpow(NULL, v1, v2);
- case LUA_OPUNM: return luai_numunm(NULL, v1);
- default: lua_assert(0); return 0;
- }
+ switch (op) {
+ case LUA_OPADD: return luai_numadd(NULL, v1, v2);
+ case LUA_OPSUB: return luai_numsub(NULL, v1, v2);
+ case LUA_OPMUL: return luai_nummul(NULL, v1, v2);
+ case LUA_OPDIV: return luai_numdiv(NULL, v1, v2);
+ case LUA_OPMOD: return luai_nummod(NULL, v1, v2);
+ case LUA_OPPOW: return luai_numpow(NULL, v1, v2);
+ case LUA_OPUNM: return luai_numunm(NULL, v1);
+ default: lua_assert(0); return 0;
+ }
}
int luaO_hexavalue (int c) {
- if (lisdigit(c)) return c - '0';
- else return ltolower(c) - 'a' + 10;
+ if (lisdigit(c)) return c - '0';
+ else return ltolower(c) - 'a' + 10;
}
@@ -96,18 +96,18 @@ int luaO_hexavalue (int c) {
static int isneg (const char **s) {
- if (**s == '-') { (*s)++; return 1; }
- else if (**s == '+') (*s)++;
- return 0;
+ if (**s == '-') { (*s)++; return 1; }
+ else if (**s == '+') (*s)++;
+ return 0;
}
static lua_Number readhexa (const char **s, lua_Number r, int *count) {
- for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */
- r = (r * cast_num(16.0)) + cast_num(1.0*luaO_hexavalue(cast_uchar(**s)));
- (*count)++;
- }
- return r;
+ for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */
+ r = (r * cast_num(16.0)) + cast_num(1.0*luaO_hexavalue(cast_uchar(**s)));
+ (*count)++;
+ }
+ return r;
}
@@ -116,172 +116,171 @@ static lua_Number readhexa (const char **s, lua_Number r, int *count) {
** C99 specification for 'strtod'
*/
static lua_Number lua_strx2number (const char *s, char **endptr) {
- lua_Number r = 0.0;
- int e = 0, i = 0;
- int neg = 0; /* 1 if number is negative */
- *endptr = cast(char *, s); /* nothing is valid yet */
- while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
- neg = isneg(&s); /* check signal */
- if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
- return 0.0; /* invalid format (no '0x') */
- s += 2; /* skip '0x' */
- r = readhexa(&s, r, &i); /* read integer part */
- if (*s == '.') {
- s++; /* skip dot */
- r = readhexa(&s, r, &e); /* read fractional part */
- }
- if (i == 0 && e == 0)
- return 0.0; /* invalid format (no digit) */
- e *= -4; /* each fractional digit divides value by 2^-4 */
- *endptr = cast(char *, s); /* valid up to here */
- if (*s == 'p' || *s == 'P') { /* exponent part? */
- int exp1 = 0;
- int neg1;
- s++; /* skip 'p' */
- neg1 = isneg(&s); /* signal */
- if (!lisdigit(cast_uchar(*s)))
- goto ret; /* must have at least one digit */
- while (lisdigit(cast_uchar(*s))) /* read exponent */
- exp1 = exp1 * 10 + *(s++) - '0';
- if (neg1) exp1 = -exp1;
- e += exp1;
- }
- *endptr = cast(char *, s); /* valid up to here */
- ret:
- if (neg) r = -r;
- return l_mathop(ldexp)(r, e);
+ lua_Number r = 0.0;
+ int e = 0, i = 0;
+ int neg = 0; /* 1 if number is negative */
+ *endptr = cast(char *, s); /* nothing is valid yet */
+ while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
+ neg = isneg(&s); /* check signal */
+ if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */
+ return 0.0; /* invalid format (no '0x') */
+ s += 2; /* skip '0x' */
+ r = readhexa(&s, r, &i); /* read integer part */
+ if (*s == '.') {
+ s++; /* skip dot */
+ r = readhexa(&s, r, &e); /* read fractional part */
+ }
+ if (i == 0 && e == 0)
+ return 0.0; /* invalid format (no digit) */
+ e *= -4; /* each fractional digit divides value by 2^-4 */
+ *endptr = cast(char *, s); /* valid up to here */
+ if (*s == 'p' || *s == 'P') { /* exponent part? */
+ int exp1 = 0;
+ int neg1;
+ s++; /* skip 'p' */
+ neg1 = isneg(&s); /* signal */
+ if (!lisdigit(cast_uchar(*s)))
+ goto ret; /* must have at least one digit */
+ while (lisdigit(cast_uchar(*s))) /* read exponent */
+ exp1 = exp1 * 10 + *(s++) - '0';
+ if (neg1) exp1 = -exp1;
+ e += exp1;
+ }
+ *endptr = cast(char *, s); /* valid up to here */
+ ret:
+ if (neg) r = -r;
+ return l_mathop(ldexp)(r, e);
}
#endif
int luaO_str2d (const char *s, size_t len, lua_Number *result) {
- char *endptr;
- if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */
- return 0;
- else if (strpbrk(s, "xX")) /* hexa? */
- *result = lua_strx2number(s, &endptr);
- else
- *result = lua_str2number(s, &endptr);
- if (endptr == s) return 0; /* nothing recognized */
- while (lisspace(cast_uchar(*endptr))) endptr++;
- return (endptr == s + len); /* OK if no trailing characters */
+ char *endptr;
+ if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */
+ return 0;
+ else if (strpbrk(s, "xX")) /* hexa? */
+ *result = lua_strx2number(s, &endptr);
+ else
+ *result = lua_str2number(s, &endptr);
+ if (endptr == s) return 0; /* nothing recognized */
+ while (lisspace(cast_uchar(*endptr))) endptr++;
+ return (endptr == s + len); /* OK if no trailing characters */
}
static void pushstr (lua_State *L, const char *str, size_t l) {
- setsvalue2s(L, L->top++, luaS_newlstr(L, str, l));
+ setsvalue2s(L, L->top++, luaS_newlstr(L, str, l));
}
/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
- int n = 0;
- for (;;) {
- const char *e = strchr(fmt, '%');
- if (e == NULL) break;
- luaD_checkstack(L, 2); /* fmt + item */
- pushstr(L, fmt, e - fmt);
- switch (*(e+1)) {
- case 's': {
- const char *s = va_arg(argp, char *);
- if (s == NULL) s = "(null)";
- pushstr(L, s, strlen(s));
- break;
- }
- case 'c': {
- char buff;
- buff = cast(char, va_arg(argp, int));
- pushstr(L, &buff, 1);
- break;
- }
- case 'd': {
- setnvalue(L->top++, cast_num(va_arg(argp, int)));
- break;
- }
- case 'f': {
- setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
- break;
- }
- case 'p': {
- char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
- int l = sprintf(buff, "%p", va_arg(argp, void *));
- pushstr(L, buff, l);
- break;
- }
- case '%': {
- pushstr(L, "%", 1);
- break;
- }
- default: {
- luaG_runerror(L,
- "invalid option " LUA_QL("%%%c") " to " LUA_QL("lua_pushfstring"),
- *(e + 1));
- }
- }
- n += 2;
- fmt = e+2;
- }
- luaD_checkstack(L, 1);
- pushstr(L, fmt, strlen(fmt));
- if (n > 0) luaV_concat(L, n + 1);
- return svalue(L->top - 1);
+ int n = 0;
+ for (;;) {
+ const char *e = strchr(fmt, '%');
+ if (e == NULL) break;
+ luaD_checkstack(L, 2); /* fmt + item */
+ pushstr(L, fmt, e - fmt);
+ switch (*(e+1)) {
+ case 's': {
+ const char *s = va_arg(argp, char *);
+ if (s == NULL) s = "(null)";
+ pushstr(L, s, strlen(s));
+ break;
+ }
+ case 'c': {
+ char buff;
+ buff = cast(char, va_arg(argp, int));
+ pushstr(L, &buff, 1);
+ break;
+ }
+ case 'd': {
+ setnvalue(L->top++, cast_num(va_arg(argp, int)));
+ break;
+ }
+ case 'f': {
+ setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
+ break;
+ }
+ case 'p': {
+ char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
+ int l = sprintf(buff, "%p", va_arg(argp, void *));
+ pushstr(L, buff, l);
+ break;
+ }
+ case '%': {
+ pushstr(L, "%", 1);
+ break;
+ }
+ default: {
+ luaG_runerror(L,
+ "invalid option " LUA_QL("%%%c") " to " LUA_QL("lua_pushfstring"),
+ *(e + 1));
+ }
+ }
+ n += 2;
+ fmt = e+2;
+ }
+ luaD_checkstack(L, 1);
+ pushstr(L, fmt, strlen(fmt));
+ if (n > 0) luaV_concat(L, n + 1);
+ return svalue(L->top - 1);
}
const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
- const char *msg;
- va_list argp;
- va_start(argp, fmt);
- msg = luaO_pushvfstring(L, fmt, argp);
- va_end(argp);
- return msg;
+ const char *msg;
+ va_list argp;
+ va_start(argp, fmt);
+ msg = luaO_pushvfstring(L, fmt, argp);
+ va_end(argp);
+ return msg;
}
/* number of chars of a literal string without the ending \0 */
-#define LL(x) (sizeof(x)/sizeof(char) - 1)
+#define LL(x) (sizeof(x)/sizeof(char) - 1)
-#define RETS "..."
-#define PRE "[string \""
-#define POS "\"]"
+#define RETS "..."
+#define PRE "[string \""
+#define POS "\"]"
-#define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) )
+#define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) )
void luaO_chunkid (char *out, const char *source, size_t bufflen) {
- size_t l = strlen(source);
- if (*source == '=') { /* 'literal' source */
- if (l <= bufflen) /* small enough? */
- memcpy(out, source + 1, l * sizeof(char));
- else { /* truncate it */
- addstr(out, source + 1, bufflen - 1);
- *out = '\0';
- }
- }
- else if (*source == '@') { /* file name */
- if (l <= bufflen) /* small enough? */
- memcpy(out, source + 1, l * sizeof(char));
- else { /* add '...' before rest of name */
- addstr(out, RETS, LL(RETS));
- bufflen -= LL(RETS);
- memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
- }
- }
- else { /* string; format as [string "source"] */
- const char *nl = strchr(source, '\n'); /* find first new line (if any) */
- addstr(out, PRE, LL(PRE)); /* add prefix */
- bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
- if (l < bufflen && nl == NULL) { /* small one-line source? */
- addstr(out, source, l); /* keep it */
- }
- else {
- if (nl != NULL) l = nl - source; /* stop at first newline */
- if (l > bufflen) l = bufflen;
- addstr(out, source, l);
- addstr(out, RETS, LL(RETS));
- }
- memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
- }
+ size_t l = strlen(source);
+ if (*source == '=') { /* 'literal' source */
+ if (l <= bufflen) /* small enough? */
+ memcpy(out, source + 1, l * sizeof(char));
+ else { /* truncate it */
+ addstr(out, source + 1, bufflen - 1);
+ *out = '\0';
+ }
+ }
+ else if (*source == '@') { /* file name */
+ if (l <= bufflen) /* small enough? */
+ memcpy(out, source + 1, l * sizeof(char));
+ else { /* add '...' before rest of name */
+ addstr(out, RETS, LL(RETS));
+ bufflen -= LL(RETS);
+ memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
+ }
+ }
+ else { /* string; format as [string "source"] */
+ const char *nl = strchr(source, '\n'); /* find first new line (if any) */
+ addstr(out, PRE, LL(PRE)); /* add prefix */
+ bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
+ if (l < bufflen && nl == NULL) { /* small one-line source? */
+ addstr(out, source, l); /* keep it */
+ }
+ else {
+ if (nl != NULL) l = nl - source; /* stop at first newline */
+ if (l > bufflen) l = bufflen;
+ addstr(out, source, l);
+ addstr(out, RETS, LL(RETS));
+ }
+ memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
+ }
}
-
diff --git a/src/lib/lua/lobject.h b/src/lib/lua/lobject.h
index dd23b9143cd..04964dc75ab 100644
--- a/src/lib/lua/lobject.h
+++ b/src/lib/lua/lobject.h
@@ -19,14 +19,14 @@
/*
** Extra tags for non-values
*/
-#define LUA_TPROTO LUA_NUMTAGS
-#define LUA_TUPVAL (LUA_NUMTAGS+1)
-#define LUA_TDEADKEY (LUA_NUMTAGS+2)
+#define LUA_TPROTO LUA_NUMTAGS
+#define LUA_TUPVAL (LUA_NUMTAGS+1)
+#define LUA_TDEADKEY (LUA_NUMTAGS+2)
/*
** number of all possible tags (including LUA_TNONE but excluding DEADKEY)
*/
-#define LUA_TOTALTAGS (LUA_TUPVAL+2)
+#define LUA_TOTALTAGS (LUA_TUPVAL+2)
/*
@@ -36,7 +36,7 @@
** bit 6: whether value is collectable
*/
-#define VARBITS (3 << 4)
+#define VARBITS (3 << 4)
/*
@@ -47,21 +47,21 @@
*/
/* Variant tags for functions */
-#define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */
-#define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */
-#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
+#define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */
+#define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */
+#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
/* Variant tags for strings */
-#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
-#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
+#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
+#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
/* Bit mark for collectable types */
-#define BIT_ISCOLLECTABLE (1 << 6)
+#define BIT_ISCOLLECTABLE (1 << 6)
/* mark a tag as collectable */
-#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
+#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
/*
@@ -74,14 +74,14 @@ typedef union GCObject GCObject;
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
*/
-#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
+#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
/*
** Common header in struct form
*/
typedef struct GCheader {
- CommonHeader;
+ CommonHeader;
} GCheader;
@@ -92,7 +92,7 @@ typedef struct GCheader {
typedef union Value Value;
-#define numfield lua_Number n; /* numbers */
+#define numfield lua_Number n; /* numbers */
@@ -101,80 +101,80 @@ typedef union Value Value;
** an actual value plus a tag with its type.
*/
-#define TValuefields Value value_; int tt_
+#define TValuefields Value value_; int tt_
typedef struct lua_TValue TValue;
/* macro defining a nil value */
-#define NILCONSTANT {NULL}, LUA_TNIL
+#define NILCONSTANT {NULL}, LUA_TNIL
-#define val_(o) ((o)->value_)
-#define num_(o) (val_(o).n)
+#define val_(o) ((o)->value_)
+#define num_(o) (val_(o).n)
/* raw type tag of a TValue */
-#define rttype(o) ((o)->tt_)
+#define rttype(o) ((o)->tt_)
/* tag with no variants (bits 0-3) */
-#define novariant(x) ((x) & 0x0F)
+#define novariant(x) ((x) & 0x0F)
/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
-#define ttype(o) (rttype(o) & 0x3F)
+#define ttype(o) (rttype(o) & 0x3F)
/* type tag of a TValue with no variants (bits 0-3) */
-#define ttypenv(o) (novariant(rttype(o)))
+#define ttypenv(o) (novariant(rttype(o)))
/* Macros to test type */
-#define checktag(o,t) (rttype(o) == (t))
-#define checktype(o,t) (ttypenv(o) == (t))
-#define ttisnumber(o) checktag((o), LUA_TNUMBER)
-#define ttisnil(o) checktag((o), LUA_TNIL)
-#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
-#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
-#define ttisstring(o) checktype((o), LUA_TSTRING)
-#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
-#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
-#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
-#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
-#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
-#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
-#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
-#define ttislcf(o) checktag((o), LUA_TLCF)
-#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA))
-#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
-#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
-
-#define ttisequal(o1,o2) (rttype(o1) == rttype(o2))
+#define checktag(o,t) (rttype(o) == (t))
+#define checktype(o,t) (ttypenv(o) == (t))
+#define ttisnumber(o) checktag((o), LUA_TNUMBER)
+#define ttisnil(o) checktag((o), LUA_TNIL)
+#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
+#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
+#define ttisstring(o) checktype((o), LUA_TSTRING)
+#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
+#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
+#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
+#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
+#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
+#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
+#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
+#define ttislcf(o) checktag((o), LUA_TLCF)
+#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA))
+#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
+#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
+
+#define ttisequal(o1,o2) (rttype(o1) == rttype(o2))
/* Macros to access values */
-#define nvalue(o) check_exp(ttisnumber(o), num_(o))
-#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
-#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
-#define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts)
-#define tsvalue(o) (&rawtsvalue(o)->tsv)
-#define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u)
-#define uvalue(o) (&rawuvalue(o)->uv)
-#define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl)
-#define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l)
-#define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)
-#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
-#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
-#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
-#define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th)
+#define nvalue(o) check_exp(ttisnumber(o), num_(o))
+#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
+#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
+#define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts)
+#define tsvalue(o) (&rawtsvalue(o)->tsv)
+#define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u)
+#define uvalue(o) (&rawuvalue(o)->uv)
+#define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl)
+#define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l)
+#define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)
+#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
+#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
+#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
+#define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th)
/* a dead value may get the 'gc' field, but cannot access its contents */
-#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
+#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
-#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
+#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
-#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
+#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
/* Macros for internal tests */
-#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
+#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
#define checkliveness(g,obj) \
lua_longassert(!iscollectable(obj) || \
@@ -182,65 +182,65 @@ typedef struct lua_TValue TValue;
/* Macros to set values */
-#define settt_(o,t) ((o)->tt_=(t))
+#define settt_(o,t) ((o)->tt_=(t))
#define setnvalue(obj,x) \
- { TValue *io=(obj); num_(io)=(x); settt_(io, LUA_TNUMBER); }
+ { TValue *io=(obj); num_(io)=(x); settt_(io, LUA_TNUMBER); }
#define setnilvalue(obj) settt_(obj, LUA_TNIL)
#define setfvalue(obj,x) \
- { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
+ { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
#define setpvalue(obj,x) \
- { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
+ { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
#define setbvalue(obj,x) \
- { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }
+ { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }
#define setgcovalue(L,obj,x) \
- { TValue *io=(obj); GCObject *i_g=(x); \
- val_(io).gc=i_g; settt_(io, ctb(gch(i_g)->tt)); }
+ { TValue *io=(obj); GCObject *i_g=(x); \
+ val_(io).gc=i_g; settt_(io, ctb(gch(i_g)->tt)); }
#define setsvalue(L,obj,x) \
- { TValue *io=(obj); \
- TString *x_ = (x); \
- val_(io).gc=cast(GCObject *, x_); settt_(io, ctb(x_->tsv.tt)); \
- checkliveness(G(L),io); }
+ { TValue *io=(obj); \
+ TString *x_ = (x); \
+ val_(io).gc=cast(GCObject *, x_); settt_(io, ctb(x_->tsv.tt)); \
+ checkliveness(G(L),io); }
#define setuvalue(L,obj,x) \
- { TValue *io=(obj); \
- val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TUSERDATA)); \
- checkliveness(G(L),io); }
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TUSERDATA)); \
+ checkliveness(G(L),io); }
#define setthvalue(L,obj,x) \
- { TValue *io=(obj); \
- val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \
- checkliveness(G(L),io); }
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \
+ checkliveness(G(L),io); }
#define setclLvalue(L,obj,x) \
- { TValue *io=(obj); \
- val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TLCL)); \
- checkliveness(G(L),io); }
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TLCL)); \
+ checkliveness(G(L),io); }
#define setclCvalue(L,obj,x) \
- { TValue *io=(obj); \
- val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TCCL)); \
- checkliveness(G(L),io); }
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TCCL)); \
+ checkliveness(G(L),io); }
#define sethvalue(L,obj,x) \
- { TValue *io=(obj); \
- val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \
- checkliveness(G(L),io); }
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \
+ checkliveness(G(L),io); }
-#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
+#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
#define setobj(L,obj1,obj2) \
{ const TValue *io2=(obj2); TValue *io1=(obj1); \
- io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
- checkliveness(G(L),io1); }
+ io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
+ checkliveness(G(L),io1); }
/*
@@ -248,23 +248,23 @@ typedef struct lua_TValue TValue;
*/
/* from stack to (same) stack */
-#define setobjs2s setobj
+#define setobjs2s setobj
/* to stack (not from same stack) */
-#define setobj2s setobj
-#define setsvalue2s setsvalue
-#define sethvalue2s sethvalue
-#define setptvalue2s setptvalue
+#define setobj2s setobj
+#define setsvalue2s setsvalue
+#define sethvalue2s sethvalue
+#define setptvalue2s setptvalue
/* from table to same table */
-#define setobjt2t setobj
+#define setobjt2t setobj
/* to table */
-#define setobj2t setobj
+#define setobj2t setobj
/* to new object */
-#define setobj2n setobj
-#define setsvalue2n setsvalue
+#define setobj2n setobj
+#define setsvalue2n setsvalue
/* check whether a number is valid (useful only for NaN trick) */
-#define luai_checknum(L,o,c) { /* empty */ }
+#define luai_checknum(L,o,c) { /* empty */ }
/*
@@ -282,7 +282,7 @@ typedef struct lua_TValue TValue;
*/
/* allows for external implementation for part of the trick */
-#if !defined(NNMARK) /* { */
+#if !defined(NNMARK) /* { */
#if !defined(LUA_IEEEENDIAN)
@@ -290,60 +290,60 @@ typedef struct lua_TValue TValue;
#endif
-#define NNMARK 0x7FF7A500
-#define NNMASK 0x7FFFFF00
+#define NNMARK 0x7FF7A500
+#define NNMASK 0x7FFFFF00
#undef TValuefields
#undef NILCONSTANT
-#if (LUA_IEEEENDIAN == 0) /* { */
+#if (LUA_IEEEENDIAN == 0) /* { */
/* little endian */
#define TValuefields \
union { struct { Value v__; int tt__; } i; double d__; } u
-#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
+#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
/* field-access macros */
-#define v_(o) ((o)->u.i.v__)
-#define d_(o) ((o)->u.d__)
-#define tt_(o) ((o)->u.i.tt__)
+#define v_(o) ((o)->u.i.v__)
+#define d_(o) ((o)->u.d__)
+#define tt_(o) ((o)->u.i.tt__)
-#else /* }{ */
+#else /* }{ */
/* big endian */
#define TValuefields \
union { struct { int tt__; Value v__; } i; double d__; } u
-#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
+#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
/* field-access macros */
-#define v_(o) ((o)->u.i.v__)
-#define d_(o) ((o)->u.d__)
-#define tt_(o) ((o)->u.i.tt__)
+#define v_(o) ((o)->u.i.v__)
+#define d_(o) ((o)->u.d__)
+#define tt_(o) ((o)->u.i.tt__)
-#endif /* } */
+#endif /* } */
-#endif /* } */
+#endif /* } */
/* correspondence with standard representation */
#undef val_
-#define val_(o) v_(o)
+#define val_(o) v_(o)
#undef num_
-#define num_(o) d_(o)
+#define num_(o) d_(o)
#undef numfield
-#define numfield /* no such field; numbers are the entire struct */
+#define numfield /* no such field; numbers are the entire struct */
/* basic check to distinguish numbers from non-numbers */
#undef ttisnumber
-#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
+#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
-#define tag2tt(t) (NNMARK | (t))
+#define tag2tt(t) (NNMARK | (t))
#undef rttype
-#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
+#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
#undef settt_
-#define settt_(o,t) (tt_(o) = tag2tt(t))
+#define settt_(o,t) (tt_(o) = tag2tt(t))
#undef setnvalue
#define setnvalue(obj,x) \
@@ -352,8 +352,8 @@ typedef struct lua_TValue TValue;
#undef setobj
#define setobj(L,obj1,obj2) \
{ const TValue *o2_=(obj2); TValue *o1_=(obj1); \
- o1_->u = o2_->u; \
- checkliveness(G(L),o1_); }
+ o1_->u = o2_->u; \
+ checkliveness(G(L),o1_); }
/*
@@ -362,8 +362,8 @@ typedef struct lua_TValue TValue;
#undef checktag
#undef checktype
-#define checktag(o,t) (tt_(o) == tag2tt(t))
-#define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS))
+#define checktag(o,t) (tt_(o) == tag2tt(t))
+#define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS))
#undef ttisequal
#define ttisequal(o1,o2) \
@@ -371,7 +371,7 @@ typedef struct lua_TValue TValue;
#undef luai_checknum
-#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; }
+#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; }
#endif
/* }====================================================== */
@@ -386,16 +386,16 @@ typedef struct lua_TValue TValue;
union Value {
- GCObject *gc; /* collectable objects */
- void *p; /* light userdata */
- int b; /* booleans */
- lua_CFunction f; /* light C functions */
- numfield /* numbers */
+ GCObject *gc; /* collectable objects */
+ void *p; /* light userdata */
+ int b; /* booleans */
+ lua_CFunction f; /* light C functions */
+ numfield /* numbers */
};
struct lua_TValue {
- TValuefields;
+ TValuefields;
};
@@ -408,18 +408,18 @@ typedef TValue *StkId; /* index to stack elements */
** Header for string value; string bytes follow the end of this structure
*/
typedef union TString {
- L_Umaxalign dummy; /* ensures maximum alignment for strings */
- struct {
- CommonHeader;
- lu_byte extra; /* reserved words for short strings; "has hash" for longs */
- unsigned int hash;
- size_t len; /* number of characters in string */
- } tsv;
+ L_Umaxalign dummy; /* ensures maximum alignment for strings */
+ struct {
+ CommonHeader;
+ lu_byte extra; /* reserved words for short strings; "has hash" for longs */
+ unsigned int hash;
+ size_t len; /* number of characters in string */
+ } tsv;
} TString;
/* get the actual string (array of bytes) from a TString */
-#define getstr(ts) cast(const char *, (ts) + 1)
+#define getstr(ts) cast(const char *, (ts) + 1)
/* get the actual string (array of bytes) from a Lua value */
#define svalue(o) getstr(rawtsvalue(o))
@@ -429,13 +429,13 @@ typedef union TString {
** Header for userdata; memory area follows the end of this structure
*/
typedef union Udata {
- L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
- struct {
- CommonHeader;
- struct Table *metatable;
- struct Table *env;
- size_t len; /* number of bytes */
- } uv;
+ L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
+ struct {
+ CommonHeader;
+ struct Table *metatable;
+ struct Table *env;
+ size_t len; /* number of bytes */
+ } uv;
} Udata;
@@ -444,9 +444,9 @@ typedef union Udata {
** Description of an upvalue for function prototypes
*/
typedef struct Upvaldesc {
- TString *name; /* upvalue name (for debug information) */
- lu_byte instack; /* whether it is in stack */
- lu_byte idx; /* index of upvalue (in stack or in outer function's list) */
+ TString *name; /* upvalue name (for debug information) */
+ lu_byte instack; /* whether it is in stack */
+ lu_byte idx; /* index of upvalue (in stack or in outer function's list) */
} Upvaldesc;
@@ -455,9 +455,9 @@ typedef struct Upvaldesc {
** (used for debug information)
*/
typedef struct LocVar {
- TString *varname;
- int startpc; /* first point where variable is active */
- int endpc; /* first point where variable is dead */
+ TString *varname;
+ int startpc; /* first point where variable is active */
+ int endpc; /* first point where variable is dead */
} LocVar;
@@ -465,27 +465,27 @@ typedef struct LocVar {
** Function Prototypes
*/
typedef struct Proto {
- CommonHeader;
- TValue *k; /* constants used by the function */
- Instruction *code;
- struct Proto **p; /* functions defined inside the function */
- int *lineinfo; /* map from opcodes to source lines (debug information) */
- LocVar *locvars; /* information about local variables (debug information) */
- Upvaldesc *upvalues; /* upvalue information */
- union Closure *cache; /* last created closure with this prototype */
- TString *source; /* used for debug information */
- int sizeupvalues; /* size of 'upvalues' */
- int sizek; /* size of `k' */
- int sizecode;
- int sizelineinfo;
- int sizep; /* size of `p' */
- int sizelocvars;
- int linedefined;
- int lastlinedefined;
- GCObject *gclist;
- lu_byte numparams; /* number of fixed parameters */
- lu_byte is_vararg;
- lu_byte maxstacksize; /* maximum stack used by this function */
+ CommonHeader;
+ TValue *k; /* constants used by the function */
+ Instruction *code;
+ struct Proto **p; /* functions defined inside the function */
+ int *lineinfo; /* map from opcodes to source lines (debug information) */
+ LocVar *locvars; /* information about local variables (debug information) */
+ Upvaldesc *upvalues; /* upvalue information */
+ union Closure *cache; /* last created closure with this prototype */
+ TString *source; /* used for debug information */
+ int sizeupvalues; /* size of 'upvalues' */
+ int sizek; /* size of `k' */
+ int sizecode;
+ int sizelineinfo;
+ int sizep; /* size of `p' */
+ int sizelocvars;
+ int linedefined;
+ int lastlinedefined;
+ GCObject *gclist;
+ lu_byte numparams; /* number of fixed parameters */
+ lu_byte is_vararg;
+ lu_byte maxstacksize; /* maximum stack used by this function */
} Proto;
@@ -494,15 +494,15 @@ typedef struct Proto {
** Lua Upvalues
*/
typedef struct UpVal {
- CommonHeader;
- TValue *v; /* points to stack or to its own value */
- union {
- TValue value; /* the value (when closed) */
- struct { /* double linked list (when open) */
- struct UpVal *prev;
- struct UpVal *next;
- } l;
- } u;
+ CommonHeader;
+ TValue *v; /* points to stack or to its own value */
+ union {
+ TValue value; /* the value (when closed) */
+ struct { /* double linked list (when open) */
+ struct UpVal *prev;
+ struct UpVal *next;
+ } l;
+ } u;
} UpVal;
@@ -514,28 +514,28 @@ typedef struct UpVal {
CommonHeader; lu_byte nupvalues; GCObject *gclist
typedef struct CClosure {
- ClosureHeader;
- lua_CFunction f;
- TValue upvalue[1]; /* list of upvalues */
+ ClosureHeader;
+ lua_CFunction f;
+ TValue upvalue[1]; /* list of upvalues */
} CClosure;
typedef struct LClosure {
- ClosureHeader;
- struct Proto *p;
- UpVal *upvals[1]; /* list of upvalues */
+ ClosureHeader;
+ struct Proto *p;
+ UpVal *upvals[1]; /* list of upvalues */
} LClosure;
typedef union Closure {
- CClosure c;
- LClosure l;
+ CClosure c;
+ LClosure l;
} Closure;
-#define isLfunction(o) ttisLclosure(o)
+#define isLfunction(o) ttisLclosure(o)
-#define getproto(o) (clLvalue(o)->p)
+#define getproto(o) (clLvalue(o)->p)
/*
@@ -543,30 +543,30 @@ typedef union Closure {
*/
typedef union TKey {
- struct {
- TValuefields;
- struct Node *next; /* for chaining */
- } nk;
- TValue tvk;
+ struct {
+ TValuefields;
+ struct Node *next; /* for chaining */
+ } nk;
+ TValue tvk;
} TKey;
typedef struct Node {
- TValue i_val;
- TKey i_key;
+ TValue i_val;
+ TKey i_key;
} Node;
typedef struct Table {
- CommonHeader;
- lu_byte flags; /* 1<<p means tagmethod(p) is not present */
- lu_byte lsizenode; /* log2 of size of `node' array */
- struct Table *metatable;
- TValue *array; /* array part */
- Node *node;
- Node *lastfree; /* any free position is before this position */
- GCObject *gclist;
- int sizearray; /* size of `array' array */
+ CommonHeader;
+ lu_byte flags; /* 1<<p means tagmethod(p) is not present */
+ lu_byte lsizenode; /* log2 of size of `node' array */
+ struct Table *metatable;
+ TValue *array; /* array part */
+ Node *node;
+ Node *lastfree; /* any free position is before this position */
+ GCObject *gclist;
+ int sizearray; /* size of `array' array */
} Table;
@@ -578,14 +578,14 @@ typedef struct Table {
(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
-#define twoto(x) (1<<(x))
-#define sizenode(t) (twoto((t)->lsizenode))
+#define twoto(x) (1<<(x))
+#define sizenode(t) (twoto((t)->lsizenode))
/*
** (address of) a fixed nil value
*/
-#define luaO_nilobject (&luaO_nilobject_)
+#define luaO_nilobject (&luaO_nilobject_)
LUAI_DDEC const TValue luaO_nilobject_;
@@ -598,10 +598,9 @@ LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2);
LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result);
LUAI_FUNC int luaO_hexavalue (int c);
LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
- va_list argp);
+ va_list argp);
LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
#endif
-
diff --git a/src/lib/lua/lopcodes.c b/src/lib/lua/lopcodes.c
index ef73692754e..009f21424a9 100644
--- a/src/lib/lua/lopcodes.c
+++ b/src/lib/lua/lopcodes.c
@@ -15,93 +15,92 @@
/* ORDER OP */
LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
- "MOVE",
- "LOADK",
- "LOADKX",
- "LOADBOOL",
- "LOADNIL",
- "GETUPVAL",
- "GETTABUP",
- "GETTABLE",
- "SETTABUP",
- "SETUPVAL",
- "SETTABLE",
- "NEWTABLE",
- "SELF",
- "ADD",
- "SUB",
- "MUL",
- "DIV",
- "MOD",
- "POW",
- "UNM",
- "NOT",
- "LEN",
- "CONCAT",
- "JMP",
- "EQ",
- "LT",
- "LE",
- "TEST",
- "TESTSET",
- "CALL",
- "TAILCALL",
- "RETURN",
- "FORLOOP",
- "FORPREP",
- "TFORCALL",
- "TFORLOOP",
- "SETLIST",
- "CLOSURE",
- "VARARG",
- "EXTRAARG",
- NULL
+ "MOVE",
+ "LOADK",
+ "LOADKX",
+ "LOADBOOL",
+ "LOADNIL",
+ "GETUPVAL",
+ "GETTABUP",
+ "GETTABLE",
+ "SETTABUP",
+ "SETUPVAL",
+ "SETTABLE",
+ "NEWTABLE",
+ "SELF",
+ "ADD",
+ "SUB",
+ "MUL",
+ "DIV",
+ "MOD",
+ "POW",
+ "UNM",
+ "NOT",
+ "LEN",
+ "CONCAT",
+ "JMP",
+ "EQ",
+ "LT",
+ "LE",
+ "TEST",
+ "TESTSET",
+ "CALL",
+ "TAILCALL",
+ "RETURN",
+ "FORLOOP",
+ "FORPREP",
+ "TFORCALL",
+ "TFORLOOP",
+ "SETLIST",
+ "CLOSURE",
+ "VARARG",
+ "EXTRAARG",
+ NULL
};
#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
-/* T A B C mode opcode */
- opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
- ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
- ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
- ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */
- ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
- ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */
- ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
- ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */
- ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */
- ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */
- ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
- ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
- ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */
- ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
- ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
- ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
- ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
- ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
- ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */
- ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
- ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
- ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
- ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
- ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
- ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
- ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
- ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
+/* T A B C mode opcode */
+ opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
+ ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
+ ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
+ ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */
+ ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
+ ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */
+ ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */
+ ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */
+ ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */
+ ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
+ ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
+ ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */
+ ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
+ ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
+ ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
+ ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
+ ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
+ ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
};
-
diff --git a/src/lib/lua/lopcodes.h b/src/lib/lua/lopcodes.h
index 07d2b3f39aa..a808e0d8c63 100644
--- a/src/lib/lua/lopcodes.h
+++ b/src/lib/lua/lopcodes.h
@@ -14,12 +14,12 @@
We assume that instructions are unsigned numbers.
All instructions have an opcode in the first 6 bits.
Instructions can have the following fields:
- `A' : 8 bits
- `B' : 9 bits
- `C' : 9 bits
- 'Ax' : 26 bits ('A', 'B', and 'C' together)
- `Bx' : 18 bits (`B' and `C' together)
- `sBx' : signed Bx
+ `A' : 8 bits
+ `B' : 9 bits
+ `C' : 9 bits
+ 'Ax' : 26 bits ('A', 'B', and 'C' together)
+ `Bx' : 18 bits (`B' and `C' together)
+ `sBx' : signed Bx
A signed argument is represented in excess K; that is, the number
value is the unsigned value minus K. K is exactly the maximum value
@@ -35,20 +35,20 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
/*
** size and position of opcode arguments.
*/
-#define SIZE_C 9
-#define SIZE_B 9
-#define SIZE_Bx (SIZE_C + SIZE_B)
-#define SIZE_A 8
-#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
+#define SIZE_C 9
+#define SIZE_B 9
+#define SIZE_Bx (SIZE_C + SIZE_B)
+#define SIZE_A 8
+#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
-#define SIZE_OP 6
+#define SIZE_OP 6
-#define POS_OP 0
-#define POS_A (POS_OP + SIZE_OP)
-#define POS_C (POS_A + SIZE_A)
-#define POS_B (POS_C + SIZE_C)
-#define POS_Bx POS_C
-#define POS_Ax POS_A
+#define POS_OP 0
+#define POS_A (POS_OP + SIZE_OP)
+#define POS_C (POS_A + SIZE_A)
+#define POS_B (POS_C + SIZE_C)
+#define POS_Bx POS_C
+#define POS_Ax POS_A
/*
@@ -65,9 +65,9 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
#endif
#if SIZE_Ax < LUAI_BITSINT-1
-#define MAXARG_Ax ((1<<SIZE_Ax)-1)
+#define MAXARG_Ax ((1<<SIZE_Ax)-1)
#else
-#define MAXARG_Ax MAX_INT
+#define MAXARG_Ax MAX_INT
#endif
@@ -77,52 +77,52 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
/* creates a mask with `n' 1 bits at position `p' */
-#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
+#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
/* creates a mask with `n' 0 bits at position `p' */
-#define MASK0(n,p) (~MASK1(n,p))
+#define MASK0(n,p) (~MASK1(n,p))
/*
** the following macros help to manipulate instructions
*/
-#define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
-#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
+#define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
+#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
-#define getarg(i,pos,size) (cast(int, ((i)>>pos) & MASK1(size,0)))
-#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
- ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
+#define getarg(i,pos,size) (cast(int, ((i)>>pos) & MASK1(size,0)))
+#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
+ ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
-#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
-#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
+#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
+#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
-#define GETARG_B(i) getarg(i, POS_B, SIZE_B)
-#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
+#define GETARG_B(i) getarg(i, POS_B, SIZE_B)
+#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
-#define GETARG_C(i) getarg(i, POS_C, SIZE_C)
-#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
+#define GETARG_C(i) getarg(i, POS_C, SIZE_C)
+#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
-#define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx)
-#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
+#define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx)
+#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
-#define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax)
-#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
+#define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax)
+#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
-#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
-#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
+#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
+#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
-#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \
+#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \
| (cast(Instruction, a)<<POS_A) \
| (cast(Instruction, b)<<POS_B) \
| (cast(Instruction, c)<<POS_C))
-#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
+#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
| (cast(Instruction, a)<<POS_A) \
| (cast(Instruction, bc)<<POS_Bx))
-#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
+#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
| (cast(Instruction, a)<<POS_Ax))
@@ -131,24 +131,24 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
*/
/* this bit 1 means constant (0 means register) */
-#define BITRK (1 << (SIZE_B - 1))
+#define BITRK (1 << (SIZE_B - 1))
/* test whether value is a constant */
-#define ISK(x) ((x) & BITRK)
+#define ISK(x) ((x) & BITRK)
/* gets the index of the constant */
-#define INDEXK(r) ((int)(r) & ~BITRK)
+#define INDEXK(r) ((int)(r) & ~BITRK)
-#define MAXINDEXRK (BITRK - 1)
+#define MAXINDEXRK (BITRK - 1)
/* code a constant index as a RK value */
-#define RKASK(x) ((x) | BITRK)
+#define RKASK(x) ((x) | BITRK)
/*
** invalid register that fits in 8 bits
*/
-#define NO_REG MAXARG_A
+#define NO_REG MAXARG_A
/*
@@ -164,68 +164,68 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
typedef enum {
/*----------------------------------------------------------------------
-name args description
+name args description
------------------------------------------------------------------------*/
-OP_MOVE,/* A B R(A) := R(B) */
-OP_LOADK,/* A Bx R(A) := Kst(Bx) */
-OP_LOADKX,/* A R(A) := Kst(extra arg) */
-OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
-OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
-OP_GETUPVAL,/* A B R(A) := UpValue[B] */
+OP_MOVE,/* A B R(A) := R(B) */
+OP_LOADK,/* A Bx R(A) := Kst(Bx) */
+OP_LOADKX,/* A R(A) := Kst(extra arg) */
+OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
+OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
+OP_GETUPVAL,/* A B R(A) := UpValue[B] */
-OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */
-OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */
+OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */
+OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */
-OP_SETTABUP,/* A B C UpValue[A][RK(B)] := RK(C) */
-OP_SETUPVAL,/* A B UpValue[B] := R(A) */
-OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */
+OP_SETTABUP,/* A B C UpValue[A][RK(B)] := RK(C) */
+OP_SETUPVAL,/* A B UpValue[B] := R(A) */
+OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */
-OP_NEWTABLE,/* A B C R(A) := {} (size = B,C) */
+OP_NEWTABLE,/* A B C R(A) := {} (size = B,C) */
-OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
+OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
-OP_ADD,/* A B C R(A) := RK(B) + RK(C) */
-OP_SUB,/* A B C R(A) := RK(B) - RK(C) */
-OP_MUL,/* A B C R(A) := RK(B) * RK(C) */
-OP_DIV,/* A B C R(A) := RK(B) / RK(C) */
-OP_MOD,/* A B C R(A) := RK(B) % RK(C) */
-OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */
-OP_UNM,/* A B R(A) := -R(B) */
-OP_NOT,/* A B R(A) := not R(B) */
-OP_LEN,/* A B R(A) := length of R(B) */
+OP_ADD,/* A B C R(A) := RK(B) + RK(C) */
+OP_SUB,/* A B C R(A) := RK(B) - RK(C) */
+OP_MUL,/* A B C R(A) := RK(B) * RK(C) */
+OP_DIV,/* A B C R(A) := RK(B) / RK(C) */
+OP_MOD,/* A B C R(A) := RK(B) % RK(C) */
+OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */
+OP_UNM,/* A B R(A) := -R(B) */
+OP_NOT,/* A B R(A) := not R(B) */
+OP_LEN,/* A B R(A) := length of R(B) */
-OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
+OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
-OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
-OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
-OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
-OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
+OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
+OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
+OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
+OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
-OP_TEST,/* A C if not (R(A) <=> C) then pc++ */
-OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */
+OP_TEST,/* A C if not (R(A) <=> C) then pc++ */
+OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */
-OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
-OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
-OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */
+OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
+OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
+OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */
-OP_FORLOOP,/* A sBx R(A)+=R(A+2);
- if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
-OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
+OP_FORLOOP,/* A sBx R(A)+=R(A+2);
+ if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
+OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
-OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
-OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
+OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
+OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
-OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
+OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
-OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */
+OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */
-OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
+OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
-OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
+OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
} OpCode;
-#define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1)
+#define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1)
@@ -263,26 +263,26 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
*/
enum OpArgMask {
- OpArgN, /* argument is not used */
- OpArgU, /* argument is used */
- OpArgR, /* argument is a register or a jump offset */
- OpArgK /* argument is a constant or register/constant */
+ OpArgN, /* argument is not used */
+ OpArgU, /* argument is used */
+ OpArgR, /* argument is a register or a jump offset */
+ OpArgK /* argument is a constant or register/constant */
};
LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];
-#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
-#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
-#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
-#define testAMode(m) (luaP_opmodes[m] & (1 << 6))
-#define testTMode(m) (luaP_opmodes[m] & (1 << 7))
+#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
+#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
+#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
+#define testAMode(m) (luaP_opmodes[m] & (1 << 6))
+#define testTMode(m) (luaP_opmodes[m] & (1 << 7))
LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
/* number of list items to accumulate before a SETLIST instruction */
-#define LFIELDS_PER_FLUSH 50
+#define LFIELDS_PER_FLUSH 50
#endif
diff --git a/src/lib/lua/loslib.c b/src/lib/lua/loslib.c
index f287e06d183..e6ff77c65f9 100644
--- a/src/lib/lua/loslib.c
+++ b/src/lib/lua/loslib.c
@@ -26,12 +26,12 @@
#if !defined(LUA_STRFTIMEOPTIONS)
#if !defined(LUA_USE_POSIX)
-#define LUA_STRFTIMEOPTIONS { "aAbBcdHIjmMpSUwWxXyYz%", "" }
+#define LUA_STRFTIMEOPTIONS { "aAbBcdHIjmMpSUwWxXyYz%", "" }
#else
#define LUA_STRFTIMEOPTIONS \
{ "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%", "" \
- "", "E", "cCxXyY", \
- "O", "deHImMSuUVwWy" }
+ "", "E", "cCxXyY", \
+ "O", "deHImMSuUVwWy" }
#endif
#endif
@@ -44,17 +44,17 @@
*/
#if defined(LUA_USE_MKSTEMP)
#include <unistd.h>
-#define LUA_TMPNAMBUFSIZE 32
+#define LUA_TMPNAMBUFSIZE 32
#define lua_tmpnam(b,e) { \
- strcpy(b, "/tmp/lua_XXXXXX"); \
- e = mkstemp(b); \
- if (e != -1) close(e); \
- e = (e == -1); }
+ strcpy(b, "/tmp/lua_XXXXXX"); \
+ e = mkstemp(b); \
+ if (e != -1) close(e); \
+ e = (e == -1); }
#elif !defined(lua_tmpnam)
-#define LUA_TMPNAMBUFSIZE L_tmpnam
-#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
+#define LUA_TMPNAMBUFSIZE L_tmpnam
+#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
#endif
@@ -65,63 +65,63 @@
*/
#if defined(LUA_USE_GMTIME_R)
-#define l_gmtime(t,r) gmtime_r(t,r)
-#define l_localtime(t,r) localtime_r(t,r)
+#define l_gmtime(t,r) gmtime_r(t,r)
+#define l_localtime(t,r) localtime_r(t,r)
#elif !defined(l_gmtime)
-#define l_gmtime(t,r) ((void)r, gmtime(t))
-#define l_localtime(t,r) ((void)r, localtime(t))
+#define l_gmtime(t,r) ((void)r, gmtime(t))
+#define l_localtime(t,r) ((void)r, localtime(t))
#endif
static int os_execute (lua_State *L) {
- const char *cmd = luaL_optstring(L, 1, NULL);
- int stat = system(cmd);
- if (cmd != NULL)
- return luaL_execresult(L, stat);
- else {
- lua_pushboolean(L, stat); /* true if there is a shell */
- return 1;
- }
+ const char *cmd = luaL_optstring(L, 1, NULL);
+ int stat = system(cmd);
+ if (cmd != NULL)
+ return luaL_execresult(L, stat);
+ else {
+ lua_pushboolean(L, stat); /* true if there is a shell */
+ return 1;
+ }
}
static int os_remove (lua_State *L) {
- const char *filename = luaL_checkstring(L, 1);
- return luaL_fileresult(L, remove(filename) == 0, filename);
+ const char *filename = luaL_checkstring(L, 1);
+ return luaL_fileresult(L, remove(filename) == 0, filename);
}
static int os_rename (lua_State *L) {
- const char *fromname = luaL_checkstring(L, 1);
- const char *toname = luaL_checkstring(L, 2);
- return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);
+ const char *fromname = luaL_checkstring(L, 1);
+ const char *toname = luaL_checkstring(L, 2);
+ return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);
}
static int os_tmpname (lua_State *L) {
- char buff[LUA_TMPNAMBUFSIZE];
- int err;
- lua_tmpnam(buff, err);
- if (err)
- return luaL_error(L, "unable to generate a unique filename");
- lua_pushstring(L, buff);
- return 1;
+ char buff[LUA_TMPNAMBUFSIZE];
+ int err;
+ lua_tmpnam(buff, err);
+ if (err)
+ return luaL_error(L, "unable to generate a unique filename");
+ lua_pushstring(L, buff);
+ return 1;
}
static int os_getenv (lua_State *L) {
- lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
- return 1;
+ lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
+ return 1;
}
static int os_clock (lua_State *L) {
- lua_pushnumber(L, ((lua_Number)(1.0*clock()))/(lua_Number)CLOCKS_PER_SEC);
- return 1;
+ lua_pushnumber(L, ((lua_Number)(1.0*clock()))/(lua_Number)CLOCKS_PER_SEC);
+ return 1;
}
@@ -134,182 +134,182 @@ static int os_clock (lua_State *L) {
*/
static void setfield (lua_State *L, const char *key, int value) {
- lua_pushinteger(L, value);
- lua_setfield(L, -2, key);
+ lua_pushinteger(L, value);
+ lua_setfield(L, -2, key);
}
static void setboolfield (lua_State *L, const char *key, int value) {
- if (value < 0) /* undefined? */
- return; /* does not set field */
- lua_pushboolean(L, value);
- lua_setfield(L, -2, key);
+ if (value < 0) /* undefined? */
+ return; /* does not set field */
+ lua_pushboolean(L, value);
+ lua_setfield(L, -2, key);
}
static int getboolfield (lua_State *L, const char *key) {
- int res;
- lua_getfield(L, -1, key);
- res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);
- lua_pop(L, 1);
- return res;
+ int res;
+ lua_getfield(L, -1, key);
+ res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ return res;
}
static int getfield (lua_State *L, const char *key, int d) {
- int res, isnum;
- lua_getfield(L, -1, key);
- res = (int)lua_tointegerx(L, -1, &isnum);
- if (!isnum) {
- if (d < 0)
- return luaL_error(L, "field " LUA_QS " missing in date table", key);
- res = d;
- }
- lua_pop(L, 1);
- return res;
+ int res, isnum;
+ lua_getfield(L, -1, key);
+ res = (int)lua_tointegerx(L, -1, &isnum);
+ if (!isnum) {
+ if (d < 0)
+ return luaL_error(L, "field " LUA_QS " missing in date table", key);
+ res = d;
+ }
+ lua_pop(L, 1);
+ return res;
}
static const char *checkoption (lua_State *L, const char *conv, char *buff) {
- static const char *const options[] = LUA_STRFTIMEOPTIONS;
- unsigned int i;
- for (i = 0; i < sizeof(options)/sizeof(options[0]); i += 2) {
- if (*conv != '\0' && strchr(options[i], *conv) != NULL) {
- buff[1] = *conv;
- if (*options[i + 1] == '\0') { /* one-char conversion specifier? */
- buff[2] = '\0'; /* end buffer */
- return conv + 1;
- }
- else if (*(conv + 1) != '\0' &&
- strchr(options[i + 1], *(conv + 1)) != NULL) {
- buff[2] = *(conv + 1); /* valid two-char conversion specifier */
- buff[3] = '\0'; /* end buffer */
- return conv + 2;
- }
- }
- }
- luaL_argerror(L, 1,
- lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv));
- return conv; /* to avoid warnings */
+ static const char *const options[] = LUA_STRFTIMEOPTIONS;
+ unsigned int i;
+ for (i = 0; i < sizeof(options)/sizeof(options[0]); i += 2) {
+ if (*conv != '\0' && strchr(options[i], *conv) != NULL) {
+ buff[1] = *conv;
+ if (*options[i + 1] == '\0') { /* one-char conversion specifier? */
+ buff[2] = '\0'; /* end buffer */
+ return conv + 1;
+ }
+ else if (*(conv + 1) != '\0' &&
+ strchr(options[i + 1], *(conv + 1)) != NULL) {
+ buff[2] = *(conv + 1); /* valid two-char conversion specifier */
+ buff[3] = '\0'; /* end buffer */
+ return conv + 2;
+ }
+ }
+ }
+ luaL_argerror(L, 1,
+ lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv));
+ return conv; /* to avoid warnings */
}
static int os_date (lua_State *L) {
- const char *s = luaL_optstring(L, 1, "%c");
- time_t t = luaL_opt(L, luaL_checknumber, 2, time(NULL));
- struct tm tmr, *stm;
- if (*s == '!') { /* UTC? */
- stm = l_gmtime(&t, &tmr);
- s++; /* skip `!' */
- }
- else
- stm = l_localtime(&t, &tmr);
- if (stm == NULL) /* invalid date? */
- lua_pushnil(L);
- else if (strcmp(s, "*t") == 0) {
- lua_createtable(L, 0, 9); /* 9 = number of fields */
- setfield(L, "sec", stm->tm_sec);
- setfield(L, "min", stm->tm_min);
- setfield(L, "hour", stm->tm_hour);
- setfield(L, "day", stm->tm_mday);
- setfield(L, "month", stm->tm_mon+1);
- setfield(L, "year", stm->tm_year+1900);
- setfield(L, "wday", stm->tm_wday+1);
- setfield(L, "yday", stm->tm_yday+1);
- setboolfield(L, "isdst", stm->tm_isdst);
- }
- else {
- char cc[4];
- luaL_Buffer b;
- cc[0] = '%';
- luaL_buffinit(L, &b);
- while (*s) {
- if (*s != '%') /* no conversion specifier? */
- luaL_addchar(&b, *s++);
- else {
- size_t reslen;
- char buff[200]; /* should be big enough for any conversion result */
- s = checkoption(L, s + 1, cc);
- reslen = strftime(buff, sizeof(buff), cc, stm);
- luaL_addlstring(&b, buff, reslen);
- }
- }
- luaL_pushresult(&b);
- }
- return 1;
+ const char *s = luaL_optstring(L, 1, "%c");
+ time_t t = luaL_opt(L, luaL_checknumber, 2, time(NULL));
+ struct tm tmr, *stm;
+ if (*s == '!') { /* UTC? */
+ stm = l_gmtime(&t, &tmr);
+ s++; /* skip `!' */
+ }
+ else
+ stm = l_localtime(&t, &tmr);
+ if (stm == NULL) /* invalid date? */
+ lua_pushnil(L);
+ else if (strcmp(s, "*t") == 0) {
+ lua_createtable(L, 0, 9); /* 9 = number of fields */
+ setfield(L, "sec", stm->tm_sec);
+ setfield(L, "min", stm->tm_min);
+ setfield(L, "hour", stm->tm_hour);
+ setfield(L, "day", stm->tm_mday);
+ setfield(L, "month", stm->tm_mon+1);
+ setfield(L, "year", stm->tm_year+1900);
+ setfield(L, "wday", stm->tm_wday+1);
+ setfield(L, "yday", stm->tm_yday+1);
+ setboolfield(L, "isdst", stm->tm_isdst);
+ }
+ else {
+ char cc[4];
+ luaL_Buffer b;
+ cc[0] = '%';
+ luaL_buffinit(L, &b);
+ while (*s) {
+ if (*s != '%') /* no conversion specifier? */
+ luaL_addchar(&b, *s++);
+ else {
+ size_t reslen;
+ char buff[200]; /* should be big enough for any conversion result */
+ s = checkoption(L, s + 1, cc);
+ reslen = strftime(buff, sizeof(buff), cc, stm);
+ luaL_addlstring(&b, buff, reslen);
+ }
+ }
+ luaL_pushresult(&b);
+ }
+ return 1;
}
static int os_time (lua_State *L) {
- time_t t;
- if (lua_isnoneornil(L, 1)) /* called without args? */
- t = time(NULL); /* get current time */
- else {
- struct tm ts;
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_settop(L, 1); /* make sure table is at the top */
- ts.tm_sec = getfield(L, "sec", 0);
- ts.tm_min = getfield(L, "min", 0);
- ts.tm_hour = getfield(L, "hour", 12);
- ts.tm_mday = getfield(L, "day", -1);
- ts.tm_mon = getfield(L, "month", -1) - 1;
- ts.tm_year = getfield(L, "year", -1) - 1900;
- ts.tm_isdst = getboolfield(L, "isdst");
- t = mktime(&ts);
- }
- if (t == (time_t)(-1))
- lua_pushnil(L);
- else
- lua_pushnumber(L, (lua_Number)t);
- return 1;
+ time_t t;
+ if (lua_isnoneornil(L, 1)) /* called without args? */
+ t = time(NULL); /* get current time */
+ else {
+ struct tm ts;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_settop(L, 1); /* make sure table is at the top */
+ ts.tm_sec = getfield(L, "sec", 0);
+ ts.tm_min = getfield(L, "min", 0);
+ ts.tm_hour = getfield(L, "hour", 12);
+ ts.tm_mday = getfield(L, "day", -1);
+ ts.tm_mon = getfield(L, "month", -1) - 1;
+ ts.tm_year = getfield(L, "year", -1) - 1900;
+ ts.tm_isdst = getboolfield(L, "isdst");
+ t = mktime(&ts);
+ }
+ if (t == (time_t)(-1))
+ lua_pushnil(L);
+ else
+ lua_pushnumber(L, (lua_Number)t);
+ return 1;
}
static int os_difftime (lua_State *L) {
- lua_pushnumber(L, difftime((luaL_checknumber(L, 1)),
- (luaL_optnumber(L, 2, 0))));
- return 1;
+ lua_pushnumber(L, difftime((luaL_checknumber(L, 1)),
+ (luaL_optnumber(L, 2, 0))));
+ return 1;
}
/* }====================================================== */
static int os_setlocale (lua_State *L) {
- static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
- LC_NUMERIC, LC_TIME};
- static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
- "numeric", "time", NULL};
- const char *l = luaL_optstring(L, 1, NULL);
- int op = luaL_checkoption(L, 2, "all", catnames);
- lua_pushstring(L, setlocale(cat[op], l));
- return 1;
+ static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
+ LC_NUMERIC, LC_TIME};
+ static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
+ "numeric", "time", NULL};
+ const char *l = luaL_optstring(L, 1, NULL);
+ int op = luaL_checkoption(L, 2, "all", catnames);
+ lua_pushstring(L, setlocale(cat[op], l));
+ return 1;
}
static int os_exit (lua_State *L) {
- int status;
- if (lua_isboolean(L, 1))
- status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);
- else
- status = luaL_optint(L, 1, EXIT_SUCCESS);
- if (lua_toboolean(L, 2))
- lua_close(L);
- if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */
- return 0;
+ int status;
+ if (lua_isboolean(L, 1))
+ status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);
+ else
+ status = luaL_optint(L, 1, EXIT_SUCCESS);
+ if (lua_toboolean(L, 2))
+ lua_close(L);
+ if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */
+ return 0;
}
static const luaL_Reg syslib[] = {
- {"clock", os_clock},
- {"date", os_date},
- {"difftime", os_difftime},
- {"execute", os_execute},
- {"exit", os_exit},
- {"getenv", os_getenv},
- {"remove", os_remove},
- {"rename", os_rename},
- {"setlocale", os_setlocale},
- {"time", os_time},
- {"tmpname", os_tmpname},
- {NULL, NULL}
+ {"clock", os_clock},
+ {"date", os_date},
+ {"difftime", os_difftime},
+ {"execute", os_execute},
+ {"exit", os_exit},
+ {"getenv", os_getenv},
+ {"remove", os_remove},
+ {"rename", os_rename},
+ {"setlocale", os_setlocale},
+ {"time", os_time},
+ {"tmpname", os_tmpname},
+ {NULL, NULL}
};
/* }====================================================== */
@@ -317,7 +317,6 @@ static const luaL_Reg syslib[] = {
LUAMOD_API int luaopen_os (lua_State *L) {
- luaL_newlib(L, syslib);
- return 1;
+ luaL_newlib(L, syslib);
+ return 1;
}
-
diff --git a/src/lib/lua/lparser.c b/src/lib/lua/lparser.c
index d8f5b4ffc5f..61afcb8f918 100644
--- a/src/lib/lua/lparser.c
+++ b/src/lib/lua/lparser.c
@@ -29,10 +29,10 @@
/* maximum number of local variables per function (must be smaller
than 250, due to the bytecode format) */
-#define MAXVARS 200
+#define MAXVARS 200
-#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
+#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
@@ -40,12 +40,12 @@
** nodes for block list (list of active blocks)
*/
typedef struct BlockCnt {
- struct BlockCnt *previous; /* chain */
- short firstlabel; /* index of first label in this block */
- short firstgoto; /* index of first pending goto in this block */
- lu_byte nactvar; /* # active locals outside the block */
- lu_byte upval; /* true if some variable in the block is an upvalue */
- lu_byte isloop; /* true if `block' is a loop */
+ struct BlockCnt *previous; /* chain */
+ short firstlabel; /* index of first label in this block */
+ short firstgoto; /* index of first pending goto in this block */
+ lu_byte nactvar; /* # active locals outside the block */
+ lu_byte upval; /* true if some variable in the block is an upvalue */
+ lu_byte isloop; /* true if `block' is a loop */
} BlockCnt;
@@ -58,137 +58,137 @@ static void expr (LexState *ls, expdesc *v);
static void anchor_token (LexState *ls) {
- /* last token from outer function must be EOS */
- lua_assert(ls->fs != NULL || ls->t.token == TK_EOS);
- if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
- TString *ts = ls->t.seminfo.ts;
- luaX_newstring(ls, getstr(ts), ts->tsv.len);
- }
+ /* last token from outer function must be EOS */
+ lua_assert(ls->fs != NULL || ls->t.token == TK_EOS);
+ if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
+ TString *ts = ls->t.seminfo.ts;
+ luaX_newstring(ls, getstr(ts), ts->tsv.len);
+ }
}
/* semantic error */
static l_noret semerror (LexState *ls, const char *msg) {
- ls->t.token = 0; /* remove 'near to' from final message */
- luaX_syntaxerror(ls, msg);
+ ls->t.token = 0; /* remove 'near to' from final message */
+ luaX_syntaxerror(ls, msg);
}
static l_noret error_expected (LexState *ls, int token) {
- luaX_syntaxerror(ls,
- luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
+ luaX_syntaxerror(ls,
+ luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
}
static l_noret errorlimit (FuncState *fs, int limit, const char *what) {
- lua_State *L = fs->ls->L;
- const char *msg;
- int line = fs->f->linedefined;
- const char *where = (line == 0)
- ? "main function"
- : luaO_pushfstring(L, "function at line %d", line);
- msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
- what, limit, where);
- luaX_syntaxerror(fs->ls, msg);
+ lua_State *L = fs->ls->L;
+ const char *msg;
+ int line = fs->f->linedefined;
+ const char *where = (line == 0)
+ ? "main function"
+ : luaO_pushfstring(L, "function at line %d", line);
+ msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
+ what, limit, where);
+ luaX_syntaxerror(fs->ls, msg);
}
static void checklimit (FuncState *fs, int v, int l, const char *what) {
- if (v > l) errorlimit(fs, l, what);
+ if (v > l) errorlimit(fs, l, what);
}
static int testnext (LexState *ls, int c) {
- if (ls->t.token == c) {
- luaX_next(ls);
- return 1;
- }
- else return 0;
+ if (ls->t.token == c) {
+ luaX_next(ls);
+ return 1;
+ }
+ else return 0;
}
static void check (LexState *ls, int c) {
- if (ls->t.token != c)
- error_expected(ls, c);
+ if (ls->t.token != c)
+ error_expected(ls, c);
}
static void checknext (LexState *ls, int c) {
- check(ls, c);
- luaX_next(ls);
+ check(ls, c);
+ luaX_next(ls);
}
-#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
+#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
static void check_match (LexState *ls, int what, int who, int where) {
- if (!testnext(ls, what)) {
- if (where == ls->linenumber)
- error_expected(ls, what);
- else {
- luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
- "%s expected (to close %s at line %d)",
- luaX_token2str(ls, what), luaX_token2str(ls, who), where));
- }
- }
+ if (!testnext(ls, what)) {
+ if (where == ls->linenumber)
+ error_expected(ls, what);
+ else {
+ luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
+ "%s expected (to close %s at line %d)",
+ luaX_token2str(ls, what), luaX_token2str(ls, who), where));
+ }
+ }
}
static TString *str_checkname (LexState *ls) {
- TString *ts;
- check(ls, TK_NAME);
- ts = ls->t.seminfo.ts;
- luaX_next(ls);
- return ts;
+ TString *ts;
+ check(ls, TK_NAME);
+ ts = ls->t.seminfo.ts;
+ luaX_next(ls);
+ return ts;
}
static void init_exp (expdesc *e, expkind k, int i) {
- e->f = e->t = NO_JUMP;
- e->k = k;
- e->u.info = i;
+ e->f = e->t = NO_JUMP;
+ e->k = k;
+ e->u.info = i;
}
static void codestring (LexState *ls, expdesc *e, TString *s) {
- init_exp(e, VK, luaK_stringK(ls->fs, s));
+ init_exp(e, VK, luaK_stringK(ls->fs, s));
}
static void checkname (LexState *ls, expdesc *e) {
- codestring(ls, e, str_checkname(ls));
+ codestring(ls, e, str_checkname(ls));
}
static int registerlocalvar (LexState *ls, TString *varname) {
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- int oldsize = f->sizelocvars;
- luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
- LocVar, SHRT_MAX, "local variables");
- while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
- f->locvars[fs->nlocvars].varname = varname;
- luaC_objbarrier(ls->L, f, varname);
- return fs->nlocvars++;
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f;
+ int oldsize = f->sizelocvars;
+ luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
+ LocVar, SHRT_MAX, "local variables");
+ while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
+ f->locvars[fs->nlocvars].varname = varname;
+ luaC_objbarrier(ls->L, f, varname);
+ return fs->nlocvars++;
}
static void new_localvar (LexState *ls, TString *name) {
- FuncState *fs = ls->fs;
- Dyndata *dyd = ls->dyd;
- int reg = registerlocalvar(ls, name);
- checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
- MAXVARS, "local variables");
- luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
- dyd->actvar.size, Vardesc, MAX_INT, "local variables");
- dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
+ FuncState *fs = ls->fs;
+ Dyndata *dyd = ls->dyd;
+ int reg = registerlocalvar(ls, name);
+ checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
+ MAXVARS, "local variables");
+ luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
+ dyd->actvar.size, Vardesc, MAX_INT, "local variables");
+ dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
}
static void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {
- new_localvar(ls, luaX_newstring(ls, name, sz));
+ new_localvar(ls, luaX_newstring(ls, name, sz));
}
#define new_localvarliteral(ls,v) \
@@ -196,60 +196,60 @@ static void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {
static LocVar *getlocvar (FuncState *fs, int i) {
- int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;
- lua_assert(idx < fs->nlocvars);
- return &fs->f->locvars[idx];
+ int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;
+ lua_assert(idx < fs->nlocvars);
+ return &fs->f->locvars[idx];
}
static void adjustlocalvars (LexState *ls, int nvars) {
- FuncState *fs = ls->fs;
- fs->nactvar = cast_byte(fs->nactvar + nvars);
- for (; nvars; nvars--) {
- getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;
- }
+ FuncState *fs = ls->fs;
+ fs->nactvar = cast_byte(fs->nactvar + nvars);
+ for (; nvars; nvars--) {
+ getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;
+ }
}
static void removevars (FuncState *fs, int tolevel) {
- fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);
- while (fs->nactvar > tolevel)
- getlocvar(fs, --fs->nactvar)->endpc = fs->pc;
+ fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);
+ while (fs->nactvar > tolevel)
+ getlocvar(fs, --fs->nactvar)->endpc = fs->pc;
}
static int searchupvalue (FuncState *fs, TString *name) {
- int i;
- Upvaldesc *up = fs->f->upvalues;
- for (i = 0; i < fs->nups; i++) {
- if (luaS_eqstr(up[i].name, name)) return i;
- }
- return -1; /* not found */
+ int i;
+ Upvaldesc *up = fs->f->upvalues;
+ for (i = 0; i < fs->nups; i++) {
+ if (luaS_eqstr(up[i].name, name)) return i;
+ }
+ return -1; /* not found */
}
static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
- Proto *f = fs->f;
- int oldsize = f->sizeupvalues;
- checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
- luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
- Upvaldesc, MAXUPVAL, "upvalues");
- while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
- f->upvalues[fs->nups].instack = (v->k == VLOCAL);
- f->upvalues[fs->nups].idx = cast_byte(v->u.info);
- f->upvalues[fs->nups].name = name;
- luaC_objbarrier(fs->ls->L, f, name);
- return fs->nups++;
+ Proto *f = fs->f;
+ int oldsize = f->sizeupvalues;
+ checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
+ luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
+ Upvaldesc, MAXUPVAL, "upvalues");
+ while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
+ f->upvalues[fs->nups].instack = (v->k == VLOCAL);
+ f->upvalues[fs->nups].idx = cast_byte(v->u.info);
+ f->upvalues[fs->nups].name = name;
+ luaC_objbarrier(fs->ls->L, f, name);
+ return fs->nups++;
}
static int searchvar (FuncState *fs, TString *n) {
- int i;
- for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {
- if (luaS_eqstr(n, getlocvar(fs, i)->varname))
- return i;
- }
- return -1; /* not found */
+ int i;
+ for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {
+ if (luaS_eqstr(n, getlocvar(fs, i)->varname))
+ return i;
+ }
+ return -1; /* not found */
}
@@ -258,9 +258,9 @@ static int searchvar (FuncState *fs, TString *n) {
(to emit close instructions later).
*/
static void markupval (FuncState *fs, int level) {
- BlockCnt *bl = fs->bl;
- while (bl->nactvar > level) bl = bl->previous;
- bl->upval = 1;
+ BlockCnt *bl = fs->bl;
+ while (bl->nactvar > level) bl = bl->previous;
+ bl->upval = 1;
}
@@ -269,92 +269,92 @@ static void markupval (FuncState *fs, int level) {
upvalue into all intermediate functions.
*/
static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
- if (fs == NULL) /* no more levels? */
- return VVOID; /* default is global */
- else {
- int v = searchvar(fs, n); /* look up locals at current level */
- if (v >= 0) { /* found? */
- init_exp(var, VLOCAL, v); /* variable is local */
- if (!base)
- markupval(fs, v); /* local will be used as an upval */
- return VLOCAL;
- }
- else { /* not found as local at current level; try upvalues */
- int idx = searchupvalue(fs, n); /* try existing upvalues */
- if (idx < 0) { /* not found? */
- if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */
- return VVOID; /* not found; is a global */
- /* else was LOCAL or UPVAL */
- idx = newupvalue(fs, n, var); /* will be a new upvalue */
- }
- init_exp(var, VUPVAL, idx);
- return VUPVAL;
- }
- }
+ if (fs == NULL) /* no more levels? */
+ return VVOID; /* default is global */
+ else {
+ int v = searchvar(fs, n); /* look up locals at current level */
+ if (v >= 0) { /* found? */
+ init_exp(var, VLOCAL, v); /* variable is local */
+ if (!base)
+ markupval(fs, v); /* local will be used as an upval */
+ return VLOCAL;
+ }
+ else { /* not found as local at current level; try upvalues */
+ int idx = searchupvalue(fs, n); /* try existing upvalues */
+ if (idx < 0) { /* not found? */
+ if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */
+ return VVOID; /* not found; is a global */
+ /* else was LOCAL or UPVAL */
+ idx = newupvalue(fs, n, var); /* will be a new upvalue */
+ }
+ init_exp(var, VUPVAL, idx);
+ return VUPVAL;
+ }
+ }
}
static void singlevar (LexState *ls, expdesc *var) {
- TString *varname = str_checkname(ls);
- FuncState *fs = ls->fs;
- if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
- expdesc key;
- singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
- lua_assert(var->k == VLOCAL || var->k == VUPVAL);
- codestring(ls, &key, varname); /* key is variable name */
- luaK_indexed(fs, var, &key); /* env[varname] */
- }
+ TString *varname = str_checkname(ls);
+ FuncState *fs = ls->fs;
+ if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
+ expdesc key;
+ singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
+ lua_assert(var->k == VLOCAL || var->k == VUPVAL);
+ codestring(ls, &key, varname); /* key is variable name */
+ luaK_indexed(fs, var, &key); /* env[varname] */
+ }
}
static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
- FuncState *fs = ls->fs;
- int extra = nvars - nexps;
- if (hasmultret(e->k)) {
- extra++; /* includes call itself */
- if (extra < 0) extra = 0;
- luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
- if (extra > 1) luaK_reserveregs(fs, extra-1);
- }
- else {
- if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
- if (extra > 0) {
- int reg = fs->freereg;
- luaK_reserveregs(fs, extra);
- luaK_nil(fs, reg, extra);
- }
- }
+ FuncState *fs = ls->fs;
+ int extra = nvars - nexps;
+ if (hasmultret(e->k)) {
+ extra++; /* includes call itself */
+ if (extra < 0) extra = 0;
+ luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
+ if (extra > 1) luaK_reserveregs(fs, extra-1);
+ }
+ else {
+ if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
+ if (extra > 0) {
+ int reg = fs->freereg;
+ luaK_reserveregs(fs, extra);
+ luaK_nil(fs, reg, extra);
+ }
+ }
}
static void enterlevel (LexState *ls) {
- lua_State *L = ls->L;
- ++L->nCcalls;
- checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "C levels");
+ lua_State *L = ls->L;
+ ++L->nCcalls;
+ checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "C levels");
}
-#define leavelevel(ls) ((ls)->L->nCcalls--)
+#define leavelevel(ls) ((ls)->L->nCcalls--)
static void closegoto (LexState *ls, int g, Labeldesc *label) {
- int i;
- FuncState *fs = ls->fs;
- Labellist *gl = &ls->dyd->gt;
- Labeldesc *gt = &gl->arr[g];
- lua_assert(luaS_eqstr(gt->name, label->name));
- if (gt->nactvar < label->nactvar) {
- TString *vname = getlocvar(fs, gt->nactvar)->varname;
- const char *msg = luaO_pushfstring(ls->L,
- "<goto %s> at line %d jumps into the scope of local " LUA_QS,
- getstr(gt->name), gt->line, getstr(vname));
- semerror(ls, msg);
- }
- luaK_patchlist(fs, gt->pc, label->pc);
- /* remove goto from pending list */
- for (i = g; i < gl->n - 1; i++)
- gl->arr[i] = gl->arr[i + 1];
- gl->n--;
+ int i;
+ FuncState *fs = ls->fs;
+ Labellist *gl = &ls->dyd->gt;
+ Labeldesc *gt = &gl->arr[g];
+ lua_assert(luaS_eqstr(gt->name, label->name));
+ if (gt->nactvar < label->nactvar) {
+ TString *vname = getlocvar(fs, gt->nactvar)->varname;
+ const char *msg = luaO_pushfstring(ls->L,
+ "<goto %s> at line %d jumps into the scope of local " LUA_QS,
+ getstr(gt->name), gt->line, getstr(vname));
+ semerror(ls, msg);
+ }
+ luaK_patchlist(fs, gt->pc, label->pc);
+ /* remove goto from pending list */
+ for (i = g; i < gl->n - 1; i++)
+ gl->arr[i] = gl->arr[i + 1];
+ gl->n--;
}
@@ -362,36 +362,36 @@ static void closegoto (LexState *ls, int g, Labeldesc *label) {
** try to close a goto with existing labels; this solves backward jumps
*/
static int findlabel (LexState *ls, int g) {
- int i;
- BlockCnt *bl = ls->fs->bl;
- Dyndata *dyd = ls->dyd;
- Labeldesc *gt = &dyd->gt.arr[g];
- /* check labels in current block for a match */
- for (i = bl->firstlabel; i < dyd->label.n; i++) {
- Labeldesc *lb = &dyd->label.arr[i];
- if (luaS_eqstr(lb->name, gt->name)) { /* correct label? */
- if (gt->nactvar > lb->nactvar &&
- (bl->upval || dyd->label.n > bl->firstlabel))
- luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
- closegoto(ls, g, lb); /* close it */
- return 1;
- }
- }
- return 0; /* label not found; cannot close goto */
+ int i;
+ BlockCnt *bl = ls->fs->bl;
+ Dyndata *dyd = ls->dyd;
+ Labeldesc *gt = &dyd->gt.arr[g];
+ /* check labels in current block for a match */
+ for (i = bl->firstlabel; i < dyd->label.n; i++) {
+ Labeldesc *lb = &dyd->label.arr[i];
+ if (luaS_eqstr(lb->name, gt->name)) { /* correct label? */
+ if (gt->nactvar > lb->nactvar &&
+ (bl->upval || dyd->label.n > bl->firstlabel))
+ luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
+ closegoto(ls, g, lb); /* close it */
+ return 1;
+ }
+ }
+ return 0; /* label not found; cannot close goto */
}
static int newlabelentry (LexState *ls, Labellist *l, TString *name,
- int line, int pc) {
- int n = l->n;
- luaM_growvector(ls->L, l->arr, n, l->size,
- Labeldesc, SHRT_MAX, "labels/gotos");
- l->arr[n].name = name;
- l->arr[n].line = line;
- l->arr[n].nactvar = ls->fs->nactvar;
- l->arr[n].pc = pc;
- l->n++;
- return n;
+ int line, int pc) {
+ int n = l->n;
+ luaM_growvector(ls->L, l->arr, n, l->size,
+ Labeldesc, SHRT_MAX, "labels/gotos");
+ l->arr[n].name = name;
+ l->arr[n].line = line;
+ l->arr[n].nactvar = ls->fs->nactvar;
+ l->arr[n].pc = pc;
+ l->n++;
+ return n;
}
@@ -400,14 +400,14 @@ static int newlabelentry (LexState *ls, Labellist *l, TString *name,
** block; solves forward jumps
*/
static void findgotos (LexState *ls, Labeldesc *lb) {
- Labellist *gl = &ls->dyd->gt;
- int i = ls->fs->bl->firstgoto;
- while (i < gl->n) {
- if (luaS_eqstr(gl->arr[i].name, lb->name))
- closegoto(ls, i, lb);
- else
- i++;
- }
+ Labellist *gl = &ls->dyd->gt;
+ int i = ls->fs->bl->firstgoto;
+ while (i < gl->n) {
+ if (luaS_eqstr(gl->arr[i].name, lb->name))
+ closegoto(ls, i, lb);
+ else
+ i++;
+ }
}
@@ -418,32 +418,32 @@ static void findgotos (LexState *ls, Labeldesc *lb) {
** upvalue), close those variables being exited.
*/
static void movegotosout (FuncState *fs, BlockCnt *bl) {
- int i = bl->firstgoto;
- Labellist *gl = &fs->ls->dyd->gt;
- /* correct pending gotos to current block and try to close it
- with visible labels */
- while (i < gl->n) {
- Labeldesc *gt = &gl->arr[i];
- if (gt->nactvar > bl->nactvar) {
- if (bl->upval)
- luaK_patchclose(fs, gt->pc, bl->nactvar);
- gt->nactvar = bl->nactvar;
- }
- if (!findlabel(fs->ls, i))
- i++; /* move to next one */
- }
+ int i = bl->firstgoto;
+ Labellist *gl = &fs->ls->dyd->gt;
+ /* correct pending gotos to current block and try to close it
+ with visible labels */
+ while (i < gl->n) {
+ Labeldesc *gt = &gl->arr[i];
+ if (gt->nactvar > bl->nactvar) {
+ if (bl->upval)
+ luaK_patchclose(fs, gt->pc, bl->nactvar);
+ gt->nactvar = bl->nactvar;
+ }
+ if (!findlabel(fs->ls, i))
+ i++; /* move to next one */
+ }
}
static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
- bl->isloop = isloop;
- bl->nactvar = fs->nactvar;
- bl->firstlabel = fs->ls->dyd->label.n;
- bl->firstgoto = fs->ls->dyd->gt.n;
- bl->upval = 0;
- bl->previous = fs->bl;
- fs->bl = bl;
- lua_assert(fs->freereg == fs->nactvar);
+ bl->isloop = isloop;
+ bl->nactvar = fs->nactvar;
+ bl->firstlabel = fs->ls->dyd->label.n;
+ bl->firstgoto = fs->ls->dyd->gt.n;
+ bl->upval = 0;
+ bl->previous = fs->bl;
+ fs->bl = bl;
+ lua_assert(fs->freereg == fs->nactvar);
}
@@ -451,9 +451,9 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
** create a label named "break" to resolve break statements
*/
static void breaklabel (LexState *ls) {
- TString *n = luaS_new(ls->L, "break");
- int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);
- findgotos(ls, &ls->dyd->label.arr[l]);
+ TString *n = luaS_new(ls->L, "break");
+ int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);
+ findgotos(ls, &ls->dyd->label.arr[l]);
}
/*
@@ -461,34 +461,34 @@ static void breaklabel (LexState *ls) {
** message when label name is a reserved word (which can only be 'break')
*/
static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
- const char *msg = isreserved(gt->name)
- ? "<%s> at line %d not inside a loop"
- : "no visible label " LUA_QS " for <goto> at line %d";
- msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
- semerror(ls, msg);
+ const char *msg = isreserved(gt->name)
+ ? "<%s> at line %d not inside a loop"
+ : "no visible label " LUA_QS " for <goto> at line %d";
+ msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
+ semerror(ls, msg);
}
static void leaveblock (FuncState *fs) {
- BlockCnt *bl = fs->bl;
- LexState *ls = fs->ls;
- if (bl->previous && bl->upval) {
- /* create a 'jump to here' to close upvalues */
- int j = luaK_jump(fs);
- luaK_patchclose(fs, j, bl->nactvar);
- luaK_patchtohere(fs, j);
- }
- if (bl->isloop)
- breaklabel(ls); /* close pending breaks */
- fs->bl = bl->previous;
- removevars(fs, bl->nactvar);
- lua_assert(bl->nactvar == fs->nactvar);
- fs->freereg = fs->nactvar; /* free registers */
- ls->dyd->label.n = bl->firstlabel; /* remove local labels */
- if (bl->previous) /* inner block? */
- movegotosout(fs, bl); /* update pending gotos to outer block */
- else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
- undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */
+ BlockCnt *bl = fs->bl;
+ LexState *ls = fs->ls;
+ if (bl->previous && bl->upval) {
+ /* create a 'jump to here' to close upvalues */
+ int j = luaK_jump(fs);
+ luaK_patchclose(fs, j, bl->nactvar);
+ luaK_patchtohere(fs, j);
+ }
+ if (bl->isloop)
+ breaklabel(ls); /* close pending breaks */
+ fs->bl = bl->previous;
+ removevars(fs, bl->nactvar);
+ lua_assert(bl->nactvar == fs->nactvar);
+ fs->freereg = fs->nactvar; /* free registers */
+ ls->dyd->label.n = bl->firstlabel; /* remove local labels */
+ if (bl->previous) /* inner block? */
+ movegotosout(fs, bl); /* update pending gotos to outer block */
+ else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
+ undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */
}
@@ -496,18 +496,18 @@ static void leaveblock (FuncState *fs) {
** adds a new prototype into list of prototypes
*/
static Proto *addprototype (LexState *ls) {
- Proto *clp;
- lua_State *L = ls->L;
- FuncState *fs = ls->fs;
- Proto *f = fs->f; /* prototype of current function */
- if (fs->np >= f->sizep) {
- int oldsize = f->sizep;
- luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions");
- while (oldsize < f->sizep) f->p[oldsize++] = NULL;
- }
- f->p[fs->np++] = clp = luaF_newproto(L);
- luaC_objbarrier(L, f, clp);
- return clp;
+ Proto *clp;
+ lua_State *L = ls->L;
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f; /* prototype of current function */
+ if (fs->np >= f->sizep) {
+ int oldsize = f->sizep;
+ luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions");
+ while (oldsize < f->sizep) f->p[oldsize++] = NULL;
+ }
+ f->p[fs->np++] = clp = luaF_newproto(L);
+ luaC_objbarrier(L, f, clp);
+ return clp;
}
@@ -518,64 +518,64 @@ static Proto *addprototype (LexState *ls) {
** are in use at that time.
*/
static void codeclosure (LexState *ls, expdesc *v) {
- FuncState *fs = ls->fs->prev;
- init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
- luaK_exp2nextreg(fs, v); /* fix it at the last register */
+ FuncState *fs = ls->fs->prev;
+ init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
+ luaK_exp2nextreg(fs, v); /* fix it at the last register */
}
static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
- lua_State *L = ls->L;
- Proto *f;
- fs->prev = ls->fs; /* linked list of funcstates */
- fs->ls = ls;
- ls->fs = fs;
- fs->pc = 0;
- fs->lasttarget = 0;
- fs->jpc = NO_JUMP;
- fs->freereg = 0;
- fs->nk = 0;
- fs->np = 0;
- fs->nups = 0;
- fs->nlocvars = 0;
- fs->nactvar = 0;
- fs->firstlocal = ls->dyd->actvar.n;
- fs->bl = NULL;
- f = fs->f;
- f->source = ls->source;
- f->maxstacksize = 2; /* registers 0/1 are always valid */
- fs->h = luaH_new(L);
- /* anchor table of constants (to avoid being collected) */
- sethvalue2s(L, L->top, fs->h);
- incr_top(L);
- enterblock(fs, bl, 0);
+ lua_State *L = ls->L;
+ Proto *f;
+ fs->prev = ls->fs; /* linked list of funcstates */
+ fs->ls = ls;
+ ls->fs = fs;
+ fs->pc = 0;
+ fs->lasttarget = 0;
+ fs->jpc = NO_JUMP;
+ fs->freereg = 0;
+ fs->nk = 0;
+ fs->np = 0;
+ fs->nups = 0;
+ fs->nlocvars = 0;
+ fs->nactvar = 0;
+ fs->firstlocal = ls->dyd->actvar.n;
+ fs->bl = NULL;
+ f = fs->f;
+ f->source = ls->source;
+ f->maxstacksize = 2; /* registers 0/1 are always valid */
+ fs->h = luaH_new(L);
+ /* anchor table of constants (to avoid being collected) */
+ sethvalue2s(L, L->top, fs->h);
+ incr_top(L);
+ enterblock(fs, bl, 0);
}
static void close_func (LexState *ls) {
- lua_State *L = ls->L;
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- luaK_ret(fs, 0, 0); /* final return */
- leaveblock(fs);
- luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
- f->sizecode = fs->pc;
- luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
- f->sizelineinfo = fs->pc;
- luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
- f->sizek = fs->nk;
- luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
- f->sizep = fs->np;
- luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
- f->sizelocvars = fs->nlocvars;
- luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);
- f->sizeupvalues = fs->nups;
- lua_assert(fs->bl == NULL);
- ls->fs = fs->prev;
- /* last token read was anchored in defunct function; must re-anchor it */
- anchor_token(ls);
- L->top--; /* pop table of constants */
- luaC_checkGC(L);
+ lua_State *L = ls->L;
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f;
+ luaK_ret(fs, 0, 0); /* final return */
+ leaveblock(fs);
+ luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
+ f->sizecode = fs->pc;
+ luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
+ f->sizelineinfo = fs->pc;
+ luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
+ f->sizek = fs->nk;
+ luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
+ f->sizep = fs->np;
+ luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
+ f->sizelocvars = fs->nlocvars;
+ luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);
+ f->sizeupvalues = fs->nups;
+ lua_assert(fs->bl == NULL);
+ ls->fs = fs->prev;
+ /* last token read was anchored in defunct function; must re-anchor it */
+ anchor_token(ls);
+ L->top--; /* pop table of constants */
+ luaC_checkGC(L);
}
@@ -591,45 +591,45 @@ static void close_func (LexState *ls) {
** so it handled in separate.
*/
static int block_follow (LexState *ls, int withuntil) {
- switch (ls->t.token) {
- case TK_ELSE: case TK_ELSEIF:
- case TK_END: case TK_EOS:
- return 1;
- case TK_UNTIL: return withuntil;
- default: return 0;
- }
+ switch (ls->t.token) {
+ case TK_ELSE: case TK_ELSEIF:
+ case TK_END: case TK_EOS:
+ return 1;
+ case TK_UNTIL: return withuntil;
+ default: return 0;
+ }
}
static void statlist (LexState *ls) {
- /* statlist -> { stat [`;'] } */
- while (!block_follow(ls, 1)) {
- if (ls->t.token == TK_RETURN) {
- statement(ls);
- return; /* 'return' must be last statement */
- }
- statement(ls);
- }
+ /* statlist -> { stat [`;'] } */
+ while (!block_follow(ls, 1)) {
+ if (ls->t.token == TK_RETURN) {
+ statement(ls);
+ return; /* 'return' must be last statement */
+ }
+ statement(ls);
+ }
}
static void fieldsel (LexState *ls, expdesc *v) {
- /* fieldsel -> ['.' | ':'] NAME */
- FuncState *fs = ls->fs;
- expdesc key;
- luaK_exp2anyregup(fs, v);
- luaX_next(ls); /* skip the dot or colon */
- checkname(ls, &key);
- luaK_indexed(fs, v, &key);
+ /* fieldsel -> ['.' | ':'] NAME */
+ FuncState *fs = ls->fs;
+ expdesc key;
+ luaK_exp2anyregup(fs, v);
+ luaX_next(ls); /* skip the dot or colon */
+ checkname(ls, &key);
+ luaK_indexed(fs, v, &key);
}
static void yindex (LexState *ls, expdesc *v) {
- /* index -> '[' expr ']' */
- luaX_next(ls); /* skip the '[' */
- expr(ls, v);
- luaK_exp2val(ls->fs, v);
- checknext(ls, ']');
+ /* index -> '[' expr ']' */
+ luaX_next(ls); /* skip the '[' */
+ expr(ls, v);
+ luaK_exp2val(ls->fs, v);
+ checknext(ls, ']');
}
@@ -641,115 +641,115 @@ static void yindex (LexState *ls, expdesc *v) {
struct ConsControl {
- expdesc v; /* last list item read */
- expdesc *t; /* table descriptor */
- int nh; /* total number of `record' elements */
- int na; /* total number of array elements */
- int tostore; /* number of array elements pending to be stored */
+ expdesc v; /* last list item read */
+ expdesc *t; /* table descriptor */
+ int nh; /* total number of `record' elements */
+ int na; /* total number of array elements */
+ int tostore; /* number of array elements pending to be stored */
};
static void recfield (LexState *ls, struct ConsControl *cc) {
- /* recfield -> (NAME | `['exp1`]') = exp1 */
- FuncState *fs = ls->fs;
- int reg = ls->fs->freereg;
- expdesc key, val;
- int rkkey;
- if (ls->t.token == TK_NAME) {
- checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
- checkname(ls, &key);
- }
- else /* ls->t.token == '[' */
- yindex(ls, &key);
- cc->nh++;
- checknext(ls, '=');
- rkkey = luaK_exp2RK(fs, &key);
- expr(ls, &val);
- luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));
- fs->freereg = reg; /* free registers */
+ /* recfield -> (NAME | `['exp1`]') = exp1 */
+ FuncState *fs = ls->fs;
+ int reg = ls->fs->freereg;
+ expdesc key, val;
+ int rkkey;
+ if (ls->t.token == TK_NAME) {
+ checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
+ checkname(ls, &key);
+ }
+ else /* ls->t.token == '[' */
+ yindex(ls, &key);
+ cc->nh++;
+ checknext(ls, '=');
+ rkkey = luaK_exp2RK(fs, &key);
+ expr(ls, &val);
+ luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));
+ fs->freereg = reg; /* free registers */
}
static void closelistfield (FuncState *fs, struct ConsControl *cc) {
- if (cc->v.k == VVOID) return; /* there is no list item */
- luaK_exp2nextreg(fs, &cc->v);
- cc->v.k = VVOID;
- if (cc->tostore == LFIELDS_PER_FLUSH) {
- luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
- cc->tostore = 0; /* no more items pending */
- }
+ if (cc->v.k == VVOID) return; /* there is no list item */
+ luaK_exp2nextreg(fs, &cc->v);
+ cc->v.k = VVOID;
+ if (cc->tostore == LFIELDS_PER_FLUSH) {
+ luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
+ cc->tostore = 0; /* no more items pending */
+ }
}
static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
- if (cc->tostore == 0) return;
- if (hasmultret(cc->v.k)) {
- luaK_setmultret(fs, &cc->v);
- luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
- cc->na--; /* do not count last expression (unknown number of elements) */
- }
- else {
- if (cc->v.k != VVOID)
- luaK_exp2nextreg(fs, &cc->v);
- luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
- }
+ if (cc->tostore == 0) return;
+ if (hasmultret(cc->v.k)) {
+ luaK_setmultret(fs, &cc->v);
+ luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
+ cc->na--; /* do not count last expression (unknown number of elements) */
+ }
+ else {
+ if (cc->v.k != VVOID)
+ luaK_exp2nextreg(fs, &cc->v);
+ luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
+ }
}
static void listfield (LexState *ls, struct ConsControl *cc) {
- /* listfield -> exp */
- expr(ls, &cc->v);
- checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
- cc->na++;
- cc->tostore++;
+ /* listfield -> exp */
+ expr(ls, &cc->v);
+ checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
+ cc->na++;
+ cc->tostore++;
}
static void field (LexState *ls, struct ConsControl *cc) {
- /* field -> listfield | recfield */
- switch(ls->t.token) {
- case TK_NAME: { /* may be 'listfield' or 'recfield' */
- if (luaX_lookahead(ls) != '=') /* expression? */
- listfield(ls, cc);
- else
- recfield(ls, cc);
- break;
- }
- case '[': {
- recfield(ls, cc);
- break;
- }
- default: {
- listfield(ls, cc);
- break;
- }
- }
+ /* field -> listfield | recfield */
+ switch(ls->t.token) {
+ case TK_NAME: { /* may be 'listfield' or 'recfield' */
+ if (luaX_lookahead(ls) != '=') /* expression? */
+ listfield(ls, cc);
+ else
+ recfield(ls, cc);
+ break;
+ }
+ case '[': {
+ recfield(ls, cc);
+ break;
+ }
+ default: {
+ listfield(ls, cc);
+ break;
+ }
+ }
}
static void constructor (LexState *ls, expdesc *t) {
- /* constructor -> '{' [ field { sep field } [sep] ] '}'
- sep -> ',' | ';' */
- FuncState *fs = ls->fs;
- int line = ls->linenumber;
- int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
- struct ConsControl cc;
- cc.na = cc.nh = cc.tostore = 0;
- cc.t = t;
- init_exp(t, VRELOCABLE, pc);
- init_exp(&cc.v, VVOID, 0); /* no value (yet) */
- luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */
- checknext(ls, '{');
- do {
- lua_assert(cc.v.k == VVOID || cc.tostore > 0);
- if (ls->t.token == '}') break;
- closelistfield(fs, &cc);
- field(ls, &cc);
- } while (testnext(ls, ',') || testnext(ls, ';'));
- check_match(ls, '}', '{', line);
- lastlistfield(fs, &cc);
- SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
- SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
+ /* constructor -> '{' [ field { sep field } [sep] ] '}'
+ sep -> ',' | ';' */
+ FuncState *fs = ls->fs;
+ int line = ls->linenumber;
+ int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
+ struct ConsControl cc;
+ cc.na = cc.nh = cc.tostore = 0;
+ cc.t = t;
+ init_exp(t, VRELOCABLE, pc);
+ init_exp(&cc.v, VVOID, 0); /* no value (yet) */
+ luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */
+ checknext(ls, '{');
+ do {
+ lua_assert(cc.v.k == VVOID || cc.tostore > 0);
+ if (ls->t.token == '}') break;
+ closelistfield(fs, &cc);
+ field(ls, &cc);
+ } while (testnext(ls, ',') || testnext(ls, ';'));
+ check_match(ls, '}', '{', line);
+ lastlistfield(fs, &cc);
+ SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
+ SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
}
/* }====================================================================== */
@@ -757,110 +757,110 @@ static void constructor (LexState *ls, expdesc *t) {
static void parlist (LexState *ls) {
- /* parlist -> [ param { `,' param } ] */
- FuncState *fs = ls->fs;
- Proto *f = fs->f;
- int nparams = 0;
- f->is_vararg = 0;
- if (ls->t.token != ')') { /* is `parlist' not empty? */
- do {
- switch (ls->t.token) {
- case TK_NAME: { /* param -> NAME */
- new_localvar(ls, str_checkname(ls));
- nparams++;
- break;
- }
- case TK_DOTS: { /* param -> `...' */
- luaX_next(ls);
- f->is_vararg = 1;
- break;
- }
- default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected");
- }
- } while (!f->is_vararg && testnext(ls, ','));
- }
- adjustlocalvars(ls, nparams);
- f->numparams = cast_byte(fs->nactvar);
- luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
+ /* parlist -> [ param { `,' param } ] */
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f;
+ int nparams = 0;
+ f->is_vararg = 0;
+ if (ls->t.token != ')') { /* is `parlist' not empty? */
+ do {
+ switch (ls->t.token) {
+ case TK_NAME: { /* param -> NAME */
+ new_localvar(ls, str_checkname(ls));
+ nparams++;
+ break;
+ }
+ case TK_DOTS: { /* param -> `...' */
+ luaX_next(ls);
+ f->is_vararg = 1;
+ break;
+ }
+ default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected");
+ }
+ } while (!f->is_vararg && testnext(ls, ','));
+ }
+ adjustlocalvars(ls, nparams);
+ f->numparams = cast_byte(fs->nactvar);
+ luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
}
static void body (LexState *ls, expdesc *e, int ismethod, int line) {
- /* body -> `(' parlist `)' block END */
- FuncState new_fs;
- BlockCnt bl;
- new_fs.f = addprototype(ls);
- new_fs.f->linedefined = line;
- open_func(ls, &new_fs, &bl);
- checknext(ls, '(');
- if (ismethod) {
- new_localvarliteral(ls, "self"); /* create 'self' parameter */
- adjustlocalvars(ls, 1);
- }
- parlist(ls);
- checknext(ls, ')');
- statlist(ls);
- new_fs.f->lastlinedefined = ls->linenumber;
- check_match(ls, TK_END, TK_FUNCTION, line);
- codeclosure(ls, e);
- close_func(ls);
+ /* body -> `(' parlist `)' block END */
+ FuncState new_fs;
+ BlockCnt bl;
+ new_fs.f = addprototype(ls);
+ new_fs.f->linedefined = line;
+ open_func(ls, &new_fs, &bl);
+ checknext(ls, '(');
+ if (ismethod) {
+ new_localvarliteral(ls, "self"); /* create 'self' parameter */
+ adjustlocalvars(ls, 1);
+ }
+ parlist(ls);
+ checknext(ls, ')');
+ statlist(ls);
+ new_fs.f->lastlinedefined = ls->linenumber;
+ check_match(ls, TK_END, TK_FUNCTION, line);
+ codeclosure(ls, e);
+ close_func(ls);
}
static int explist (LexState *ls, expdesc *v) {
- /* explist -> expr { `,' expr } */
- int n = 1; /* at least one expression */
- expr(ls, v);
- while (testnext(ls, ',')) {
- luaK_exp2nextreg(ls->fs, v);
- expr(ls, v);
- n++;
- }
- return n;
+ /* explist -> expr { `,' expr } */
+ int n = 1; /* at least one expression */
+ expr(ls, v);
+ while (testnext(ls, ',')) {
+ luaK_exp2nextreg(ls->fs, v);
+ expr(ls, v);
+ n++;
+ }
+ return n;
}
static void funcargs (LexState *ls, expdesc *f, int line) {
- FuncState *fs = ls->fs;
- expdesc args;
- int base, nparams;
- switch (ls->t.token) {
- case '(': { /* funcargs -> `(' [ explist ] `)' */
- luaX_next(ls);
- if (ls->t.token == ')') /* arg list is empty? */
- args.k = VVOID;
- else {
- explist(ls, &args);
- luaK_setmultret(fs, &args);
- }
- check_match(ls, ')', '(', line);
- break;
- }
- case '{': { /* funcargs -> constructor */
- constructor(ls, &args);
- break;
- }
- case TK_STRING: { /* funcargs -> STRING */
- codestring(ls, &args, ls->t.seminfo.ts);
- luaX_next(ls); /* must use `seminfo' before `next' */
- break;
- }
- default: {
- luaX_syntaxerror(ls, "function arguments expected");
- }
- }
- lua_assert(f->k == VNONRELOC);
- base = f->u.info; /* base register for call */
- if (hasmultret(args.k))
- nparams = LUA_MULTRET; /* open call */
- else {
- if (args.k != VVOID)
- luaK_exp2nextreg(fs, &args); /* close last argument */
- nparams = fs->freereg - (base+1);
- }
- init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
- luaK_fixline(fs, line);
- fs->freereg = base+1; /* call remove function and arguments and leaves
+ FuncState *fs = ls->fs;
+ expdesc args;
+ int base, nparams;
+ switch (ls->t.token) {
+ case '(': { /* funcargs -> `(' [ explist ] `)' */
+ luaX_next(ls);
+ if (ls->t.token == ')') /* arg list is empty? */
+ args.k = VVOID;
+ else {
+ explist(ls, &args);
+ luaK_setmultret(fs, &args);
+ }
+ check_match(ls, ')', '(', line);
+ break;
+ }
+ case '{': { /* funcargs -> constructor */
+ constructor(ls, &args);
+ break;
+ }
+ case TK_STRING: { /* funcargs -> STRING */
+ codestring(ls, &args, ls->t.seminfo.ts);
+ luaX_next(ls); /* must use `seminfo' before `next' */
+ break;
+ }
+ default: {
+ luaX_syntaxerror(ls, "function arguments expected");
+ }
+ }
+ lua_assert(f->k == VNONRELOC);
+ base = f->u.info; /* base register for call */
+ if (hasmultret(args.k))
+ nparams = LUA_MULTRET; /* open call */
+ else {
+ if (args.k != VVOID)
+ luaK_exp2nextreg(fs, &args); /* close last argument */
+ nparams = fs->freereg - (base+1);
+ }
+ init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
+ luaK_fixline(fs, line);
+ fs->freereg = base+1; /* call remove function and arguments and leaves
(unless changed) one result */
}
@@ -875,159 +875,159 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
static void primaryexp (LexState *ls, expdesc *v) {
- /* primaryexp -> NAME | '(' expr ')' */
- switch (ls->t.token) {
- case '(': {
- int line = ls->linenumber;
- luaX_next(ls);
- expr(ls, v);
- check_match(ls, ')', '(', line);
- luaK_dischargevars(ls->fs, v);
- return;
- }
- case TK_NAME: {
- singlevar(ls, v);
- return;
- }
- default: {
- luaX_syntaxerror(ls, "unexpected symbol");
- }
- }
+ /* primaryexp -> NAME | '(' expr ')' */
+ switch (ls->t.token) {
+ case '(': {
+ int line = ls->linenumber;
+ luaX_next(ls);
+ expr(ls, v);
+ check_match(ls, ')', '(', line);
+ luaK_dischargevars(ls->fs, v);
+ return;
+ }
+ case TK_NAME: {
+ singlevar(ls, v);
+ return;
+ }
+ default: {
+ luaX_syntaxerror(ls, "unexpected symbol");
+ }
+ }
}
static void suffixedexp (LexState *ls, expdesc *v) {
- /* suffixedexp ->
- primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
- FuncState *fs = ls->fs;
- int line = ls->linenumber;
- primaryexp(ls, v);
- for (;;) {
- switch (ls->t.token) {
- case '.': { /* fieldsel */
- fieldsel(ls, v);
- break;
- }
- case '[': { /* `[' exp1 `]' */
- expdesc key;
- luaK_exp2anyregup(fs, v);
- yindex(ls, &key);
- luaK_indexed(fs, v, &key);
- break;
- }
- case ':': { /* `:' NAME funcargs */
- expdesc key;
- luaX_next(ls);
- checkname(ls, &key);
- luaK_self(fs, v, &key);
- funcargs(ls, v, line);
- break;
- }
- case '(': case TK_STRING: case '{': { /* funcargs */
- luaK_exp2nextreg(fs, v);
- funcargs(ls, v, line);
- break;
- }
- default: return;
- }
- }
+ /* suffixedexp ->
+ primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
+ FuncState *fs = ls->fs;
+ int line = ls->linenumber;
+ primaryexp(ls, v);
+ for (;;) {
+ switch (ls->t.token) {
+ case '.': { /* fieldsel */
+ fieldsel(ls, v);
+ break;
+ }
+ case '[': { /* `[' exp1 `]' */
+ expdesc key;
+ luaK_exp2anyregup(fs, v);
+ yindex(ls, &key);
+ luaK_indexed(fs, v, &key);
+ break;
+ }
+ case ':': { /* `:' NAME funcargs */
+ expdesc key;
+ luaX_next(ls);
+ checkname(ls, &key);
+ luaK_self(fs, v, &key);
+ funcargs(ls, v, line);
+ break;
+ }
+ case '(': case TK_STRING: case '{': { /* funcargs */
+ luaK_exp2nextreg(fs, v);
+ funcargs(ls, v, line);
+ break;
+ }
+ default: return;
+ }
+ }
}
static void simpleexp (LexState *ls, expdesc *v) {
- /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
- constructor | FUNCTION body | suffixedexp */
- switch (ls->t.token) {
- case TK_NUMBER: {
- init_exp(v, VKNUM, 0);
- v->u.nval = ls->t.seminfo.r;
- break;
- }
- case TK_STRING: {
- codestring(ls, v, ls->t.seminfo.ts);
- break;
- }
- case TK_NIL: {
- init_exp(v, VNIL, 0);
- break;
- }
- case TK_TRUE: {
- init_exp(v, VTRUE, 0);
- break;
- }
- case TK_FALSE: {
- init_exp(v, VFALSE, 0);
- break;
- }
- case TK_DOTS: { /* vararg */
- FuncState *fs = ls->fs;
- check_condition(ls, fs->f->is_vararg,
- "cannot use " LUA_QL("...") " outside a vararg function");
- init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
- break;
- }
- case '{': { /* constructor */
- constructor(ls, v);
- return;
- }
- case TK_FUNCTION: {
- luaX_next(ls);
- body(ls, v, 0, ls->linenumber);
- return;
- }
- default: {
- suffixedexp(ls, v);
- return;
- }
- }
- luaX_next(ls);
+ /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
+ constructor | FUNCTION body | suffixedexp */
+ switch (ls->t.token) {
+ case TK_NUMBER: {
+ init_exp(v, VKNUM, 0);
+ v->u.nval = ls->t.seminfo.r;
+ break;
+ }
+ case TK_STRING: {
+ codestring(ls, v, ls->t.seminfo.ts);
+ break;
+ }
+ case TK_NIL: {
+ init_exp(v, VNIL, 0);
+ break;
+ }
+ case TK_TRUE: {
+ init_exp(v, VTRUE, 0);
+ break;
+ }
+ case TK_FALSE: {
+ init_exp(v, VFALSE, 0);
+ break;
+ }
+ case TK_DOTS: { /* vararg */
+ FuncState *fs = ls->fs;
+ check_condition(ls, fs->f->is_vararg,
+ "cannot use " LUA_QL("...") " outside a vararg function");
+ init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
+ break;
+ }
+ case '{': { /* constructor */
+ constructor(ls, v);
+ return;
+ }
+ case TK_FUNCTION: {
+ luaX_next(ls);
+ body(ls, v, 0, ls->linenumber);
+ return;
+ }
+ default: {
+ suffixedexp(ls, v);
+ return;
+ }
+ }
+ luaX_next(ls);
}
static UnOpr getunopr (int op) {
- switch (op) {
- case TK_NOT: return OPR_NOT;
- case '-': return OPR_MINUS;
- case '#': return OPR_LEN;
- default: return OPR_NOUNOPR;
- }
+ switch (op) {
+ case TK_NOT: return OPR_NOT;
+ case '-': return OPR_MINUS;
+ case '#': return OPR_LEN;
+ default: return OPR_NOUNOPR;
+ }
}
static BinOpr getbinopr (int op) {
- switch (op) {
- case '+': return OPR_ADD;
- case '-': return OPR_SUB;
- case '*': return OPR_MUL;
- case '/': return OPR_DIV;
- case '%': return OPR_MOD;
- case '^': return OPR_POW;
- case TK_CONCAT: return OPR_CONCAT;
- case TK_NE: return OPR_NE;
- case TK_EQ: return OPR_EQ;
- case '<': return OPR_LT;
- case TK_LE: return OPR_LE;
- case '>': return OPR_GT;
- case TK_GE: return OPR_GE;
- case TK_AND: return OPR_AND;
- case TK_OR: return OPR_OR;
- default: return OPR_NOBINOPR;
- }
+ switch (op) {
+ case '+': return OPR_ADD;
+ case '-': return OPR_SUB;
+ case '*': return OPR_MUL;
+ case '/': return OPR_DIV;
+ case '%': return OPR_MOD;
+ case '^': return OPR_POW;
+ case TK_CONCAT: return OPR_CONCAT;
+ case TK_NE: return OPR_NE;
+ case TK_EQ: return OPR_EQ;
+ case '<': return OPR_LT;
+ case TK_LE: return OPR_LE;
+ case '>': return OPR_GT;
+ case TK_GE: return OPR_GE;
+ case TK_AND: return OPR_AND;
+ case TK_OR: return OPR_OR;
+ default: return OPR_NOBINOPR;
+ }
}
static const struct {
- lu_byte left; /* left priority for each binary operator */
- lu_byte right; /* right priority */
+ lu_byte left; /* left priority for each binary operator */
+ lu_byte right; /* right priority */
} priority[] = { /* ORDER OPR */
- {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
- {10, 9}, {5, 4}, /* ^, .. (right associative) */
- {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
- {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
- {2, 2}, {1, 1} /* and, or */
+ {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
+ {10, 9}, {5, 4}, /* ^, .. (right associative) */
+ {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
+ {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
+ {2, 2}, {1, 1} /* and, or */
};
-#define UNARY_PRIORITY 8 /* priority for unary operators */
+#define UNARY_PRIORITY 8 /* priority for unary operators */
/*
@@ -1035,37 +1035,37 @@ static const struct {
** where `binop' is any binary operator with a priority higher than `limit'
*/
static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
- BinOpr op;
- UnOpr uop;
- enterlevel(ls);
- uop = getunopr(ls->t.token);
- if (uop != OPR_NOUNOPR) {
- int line = ls->linenumber;
- luaX_next(ls);
- subexpr(ls, v, UNARY_PRIORITY);
- luaK_prefix(ls->fs, uop, v, line);
- }
- else simpleexp(ls, v);
- /* expand while operators have priorities higher than `limit' */
- op = getbinopr(ls->t.token);
- while (op != OPR_NOBINOPR && priority[op].left > limit) {
- expdesc v2;
- BinOpr nextop;
- int line = ls->linenumber;
- luaX_next(ls);
- luaK_infix(ls->fs, op, v);
- /* read sub-expression with higher priority */
- nextop = subexpr(ls, &v2, priority[op].right);
- luaK_posfix(ls->fs, op, v, &v2, line);
- op = nextop;
- }
- leavelevel(ls);
- return op; /* return first untreated operator */
+ BinOpr op;
+ UnOpr uop;
+ enterlevel(ls);
+ uop = getunopr(ls->t.token);
+ if (uop != OPR_NOUNOPR) {
+ int line = ls->linenumber;
+ luaX_next(ls);
+ subexpr(ls, v, UNARY_PRIORITY);
+ luaK_prefix(ls->fs, uop, v, line);
+ }
+ else simpleexp(ls, v);
+ /* expand while operators have priorities higher than `limit' */
+ op = getbinopr(ls->t.token);
+ while (op != OPR_NOBINOPR && priority[op].left > limit) {
+ expdesc v2;
+ BinOpr nextop;
+ int line = ls->linenumber;
+ luaX_next(ls);
+ luaK_infix(ls->fs, op, v);
+ /* read sub-expression with higher priority */
+ nextop = subexpr(ls, &v2, priority[op].right);
+ luaK_posfix(ls->fs, op, v, &v2, line);
+ op = nextop;
+ }
+ leavelevel(ls);
+ return op; /* return first untreated operator */
}
static void expr (LexState *ls, expdesc *v) {
- subexpr(ls, v, 0);
+ subexpr(ls, v, 0);
}
/* }==================================================================== */
@@ -1080,12 +1080,12 @@ static void expr (LexState *ls, expdesc *v) {
static void block (LexState *ls) {
- /* block -> statlist */
- FuncState *fs = ls->fs;
- BlockCnt bl;
- enterblock(fs, &bl, 0);
- statlist(ls);
- leaveblock(fs);
+ /* block -> statlist */
+ FuncState *fs = ls->fs;
+ BlockCnt bl;
+ enterblock(fs, &bl, 0);
+ statlist(ls);
+ leaveblock(fs);
}
@@ -1094,8 +1094,8 @@ static void block (LexState *ls) {
** assignment
*/
struct LHS_assign {
- struct LHS_assign *prev;
- expdesc v; /* variable (global, local, upvalue, or indexed) */
+ struct LHS_assign *prev;
+ expdesc v; /* variable (global, local, upvalue, or indexed) */
};
@@ -1106,492 +1106,492 @@ struct LHS_assign {
** use this safe copy in the previous assignment.
*/
static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
- FuncState *fs = ls->fs;
- int extra = fs->freereg; /* eventual position to save local variable */
- int conflict = 0;
- for (; lh; lh = lh->prev) { /* check all previous assignments */
- if (lh->v.k == VINDEXED) { /* assigning to a table? */
- /* table is the upvalue/local being assigned now? */
- if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
- conflict = 1;
- lh->v.u.ind.vt = VLOCAL;
- lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
- }
- /* index is the local being assigned? (index cannot be upvalue) */
- if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
- conflict = 1;
- lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
- }
- }
- }
- if (conflict) {
- /* copy upvalue/local value to a temporary (in position 'extra') */
- OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
- luaK_codeABC(fs, op, extra, v->u.info, 0);
- luaK_reserveregs(fs, 1);
- }
+ FuncState *fs = ls->fs;
+ int extra = fs->freereg; /* eventual position to save local variable */
+ int conflict = 0;
+ for (; lh; lh = lh->prev) { /* check all previous assignments */
+ if (lh->v.k == VINDEXED) { /* assigning to a table? */
+ /* table is the upvalue/local being assigned now? */
+ if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
+ conflict = 1;
+ lh->v.u.ind.vt = VLOCAL;
+ lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
+ }
+ /* index is the local being assigned? (index cannot be upvalue) */
+ if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
+ conflict = 1;
+ lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
+ }
+ }
+ }
+ if (conflict) {
+ /* copy upvalue/local value to a temporary (in position 'extra') */
+ OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
+ luaK_codeABC(fs, op, extra, v->u.info, 0);
+ luaK_reserveregs(fs, 1);
+ }
}
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
- expdesc e;
- check_condition(ls, vkisvar(lh->v.k), "syntax error");
- if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
- struct LHS_assign nv;
- nv.prev = lh;
- suffixedexp(ls, &nv.v);
- if (nv.v.k != VINDEXED)
- check_conflict(ls, lh, &nv.v);
- checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
- "C levels");
- assignment(ls, &nv, nvars+1);
- }
- else { /* assignment -> `=' explist */
- int nexps;
- checknext(ls, '=');
- nexps = explist(ls, &e);
- if (nexps != nvars) {
- adjust_assign(ls, nvars, nexps, &e);
- if (nexps > nvars)
- ls->fs->freereg -= nexps - nvars; /* remove extra values */
- }
- else {
- luaK_setoneret(ls->fs, &e); /* close last expression */
- luaK_storevar(ls->fs, &lh->v, &e);
- return; /* avoid default */
- }
- }
- init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
- luaK_storevar(ls->fs, &lh->v, &e);
+ expdesc e;
+ check_condition(ls, vkisvar(lh->v.k), "syntax error");
+ if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
+ struct LHS_assign nv;
+ nv.prev = lh;
+ suffixedexp(ls, &nv.v);
+ if (nv.v.k != VINDEXED)
+ check_conflict(ls, lh, &nv.v);
+ checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
+ "C levels");
+ assignment(ls, &nv, nvars+1);
+ }
+ else { /* assignment -> `=' explist */
+ int nexps;
+ checknext(ls, '=');
+ nexps = explist(ls, &e);
+ if (nexps != nvars) {
+ adjust_assign(ls, nvars, nexps, &e);
+ if (nexps > nvars)
+ ls->fs->freereg -= nexps - nvars; /* remove extra values */
+ }
+ else {
+ luaK_setoneret(ls->fs, &e); /* close last expression */
+ luaK_storevar(ls->fs, &lh->v, &e);
+ return; /* avoid default */
+ }
+ }
+ init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
+ luaK_storevar(ls->fs, &lh->v, &e);
}
static int cond (LexState *ls) {
- /* cond -> exp */
- expdesc v;
- expr(ls, &v); /* read condition */
- if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */
- luaK_goiftrue(ls->fs, &v);
- return v.f;
+ /* cond -> exp */
+ expdesc v;
+ expr(ls, &v); /* read condition */
+ if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */
+ luaK_goiftrue(ls->fs, &v);
+ return v.f;
}
static void gotostat (LexState *ls, int pc) {
- int line = ls->linenumber;
- TString *label;
- int g;
- if (testnext(ls, TK_GOTO))
- label = str_checkname(ls);
- else {
- luaX_next(ls); /* skip break */
- label = luaS_new(ls->L, "break");
- }
- g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);
- findlabel(ls, g); /* close it if label already defined */
+ int line = ls->linenumber;
+ TString *label;
+ int g;
+ if (testnext(ls, TK_GOTO))
+ label = str_checkname(ls);
+ else {
+ luaX_next(ls); /* skip break */
+ label = luaS_new(ls->L, "break");
+ }
+ g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);
+ findlabel(ls, g); /* close it if label already defined */
}
/* check for repeated labels on the same block */
static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {
- int i;
- for (i = fs->bl->firstlabel; i < ll->n; i++) {
- if (luaS_eqstr(label, ll->arr[i].name)) {
- const char *msg = luaO_pushfstring(fs->ls->L,
- "label " LUA_QS " already defined on line %d",
- getstr(label), ll->arr[i].line);
- semerror(fs->ls, msg);
- }
- }
+ int i;
+ for (i = fs->bl->firstlabel; i < ll->n; i++) {
+ if (luaS_eqstr(label, ll->arr[i].name)) {
+ const char *msg = luaO_pushfstring(fs->ls->L,
+ "label " LUA_QS " already defined on line %d",
+ getstr(label), ll->arr[i].line);
+ semerror(fs->ls, msg);
+ }
+ }
}
/* skip no-op statements */
static void skipnoopstat (LexState *ls) {
- while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
- statement(ls);
+ while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
+ statement(ls);
}
static void labelstat (LexState *ls, TString *label, int line) {
- /* label -> '::' NAME '::' */
- FuncState *fs = ls->fs;
- Labellist *ll = &ls->dyd->label;
- int l; /* index of new label being created */
- checkrepeated(fs, ll, label); /* check for repeated labels */
- checknext(ls, TK_DBCOLON); /* skip double colon */
- /* create new entry for this label */
- l = newlabelentry(ls, ll, label, line, fs->pc);
- skipnoopstat(ls); /* skip other no-op statements */
- if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
- /* assume that locals are already out of scope */
- ll->arr[l].nactvar = fs->bl->nactvar;
- }
- findgotos(ls, &ll->arr[l]);
+ /* label -> '::' NAME '::' */
+ FuncState *fs = ls->fs;
+ Labellist *ll = &ls->dyd->label;
+ int l; /* index of new label being created */
+ checkrepeated(fs, ll, label); /* check for repeated labels */
+ checknext(ls, TK_DBCOLON); /* skip double colon */
+ /* create new entry for this label */
+ l = newlabelentry(ls, ll, label, line, fs->pc);
+ skipnoopstat(ls); /* skip other no-op statements */
+ if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
+ /* assume that locals are already out of scope */
+ ll->arr[l].nactvar = fs->bl->nactvar;
+ }
+ findgotos(ls, &ll->arr[l]);
}
static void whilestat (LexState *ls, int line) {
- /* whilestat -> WHILE cond DO block END */
- FuncState *fs = ls->fs;
- int whileinit;
- int condexit;
- BlockCnt bl;
- luaX_next(ls); /* skip WHILE */
- whileinit = luaK_getlabel(fs);
- condexit = cond(ls);
- enterblock(fs, &bl, 1);
- checknext(ls, TK_DO);
- block(ls);
- luaK_jumpto(fs, whileinit);
- check_match(ls, TK_END, TK_WHILE, line);
- leaveblock(fs);
- luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
+ /* whilestat -> WHILE cond DO block END */
+ FuncState *fs = ls->fs;
+ int whileinit;
+ int condexit;
+ BlockCnt bl;
+ luaX_next(ls); /* skip WHILE */
+ whileinit = luaK_getlabel(fs);
+ condexit = cond(ls);
+ enterblock(fs, &bl, 1);
+ checknext(ls, TK_DO);
+ block(ls);
+ luaK_jumpto(fs, whileinit);
+ check_match(ls, TK_END, TK_WHILE, line);
+ leaveblock(fs);
+ luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
}
static void repeatstat (LexState *ls, int line) {
- /* repeatstat -> REPEAT block UNTIL cond */
- int condexit;
- FuncState *fs = ls->fs;
- int repeat_init = luaK_getlabel(fs);
- BlockCnt bl1, bl2;
- enterblock(fs, &bl1, 1); /* loop block */
- enterblock(fs, &bl2, 0); /* scope block */
- luaX_next(ls); /* skip REPEAT */
- statlist(ls);
- check_match(ls, TK_UNTIL, TK_REPEAT, line);
- condexit = cond(ls); /* read condition (inside scope block) */
- if (bl2.upval) /* upvalues? */
- luaK_patchclose(fs, condexit, bl2.nactvar);
- leaveblock(fs); /* finish scope */
- luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
- leaveblock(fs); /* finish loop */
+ /* repeatstat -> REPEAT block UNTIL cond */
+ int condexit;
+ FuncState *fs = ls->fs;
+ int repeat_init = luaK_getlabel(fs);
+ BlockCnt bl1, bl2;
+ enterblock(fs, &bl1, 1); /* loop block */
+ enterblock(fs, &bl2, 0); /* scope block */
+ luaX_next(ls); /* skip REPEAT */
+ statlist(ls);
+ check_match(ls, TK_UNTIL, TK_REPEAT, line);
+ condexit = cond(ls); /* read condition (inside scope block) */
+ if (bl2.upval) /* upvalues? */
+ luaK_patchclose(fs, condexit, bl2.nactvar);
+ leaveblock(fs); /* finish scope */
+ luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
+ leaveblock(fs); /* finish loop */
}
static int exp1 (LexState *ls) {
- expdesc e;
- int reg;
- expr(ls, &e);
- luaK_exp2nextreg(ls->fs, &e);
- lua_assert(e.k == VNONRELOC);
- reg = e.u.info;
- return reg;
+ expdesc e;
+ int reg;
+ expr(ls, &e);
+ luaK_exp2nextreg(ls->fs, &e);
+ lua_assert(e.k == VNONRELOC);
+ reg = e.u.info;
+ return reg;
}
static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
- /* forbody -> DO block */
- BlockCnt bl;
- FuncState *fs = ls->fs;
- int prep, endfor;
- adjustlocalvars(ls, 3); /* control variables */
- checknext(ls, TK_DO);
- prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
- enterblock(fs, &bl, 0); /* scope for declared variables */
- adjustlocalvars(ls, nvars);
- luaK_reserveregs(fs, nvars);
- block(ls);
- leaveblock(fs); /* end of scope for declared variables */
- luaK_patchtohere(fs, prep);
- if (isnum) /* numeric for? */
- endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
- else { /* generic for */
- luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
- luaK_fixline(fs, line);
- endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);
- }
- luaK_patchlist(fs, endfor, prep + 1);
- luaK_fixline(fs, line);
+ /* forbody -> DO block */
+ BlockCnt bl;
+ FuncState *fs = ls->fs;
+ int prep, endfor;
+ adjustlocalvars(ls, 3); /* control variables */
+ checknext(ls, TK_DO);
+ prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
+ enterblock(fs, &bl, 0); /* scope for declared variables */
+ adjustlocalvars(ls, nvars);
+ luaK_reserveregs(fs, nvars);
+ block(ls);
+ leaveblock(fs); /* end of scope for declared variables */
+ luaK_patchtohere(fs, prep);
+ if (isnum) /* numeric for? */
+ endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
+ else { /* generic for */
+ luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
+ luaK_fixline(fs, line);
+ endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);
+ }
+ luaK_patchlist(fs, endfor, prep + 1);
+ luaK_fixline(fs, line);
}
static void fornum (LexState *ls, TString *varname, int line) {
- /* fornum -> NAME = exp1,exp1[,exp1] forbody */
- FuncState *fs = ls->fs;
- int base = fs->freereg;
- new_localvarliteral(ls, "(for index)");
- new_localvarliteral(ls, "(for limit)");
- new_localvarliteral(ls, "(for step)");
- new_localvar(ls, varname);
- checknext(ls, '=');
- exp1(ls); /* initial value */
- checknext(ls, ',');
- exp1(ls); /* limit */
- if (testnext(ls, ','))
- exp1(ls); /* optional step */
- else { /* default step = 1 */
- luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1));
- luaK_reserveregs(fs, 1);
- }
- forbody(ls, base, line, 1, 1);
+ /* fornum -> NAME = exp1,exp1[,exp1] forbody */
+ FuncState *fs = ls->fs;
+ int base = fs->freereg;
+ new_localvarliteral(ls, "(for index)");
+ new_localvarliteral(ls, "(for limit)");
+ new_localvarliteral(ls, "(for step)");
+ new_localvar(ls, varname);
+ checknext(ls, '=');
+ exp1(ls); /* initial value */
+ checknext(ls, ',');
+ exp1(ls); /* limit */
+ if (testnext(ls, ','))
+ exp1(ls); /* optional step */
+ else { /* default step = 1 */
+ luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1));
+ luaK_reserveregs(fs, 1);
+ }
+ forbody(ls, base, line, 1, 1);
}
static void forlist (LexState *ls, TString *indexname) {
- /* forlist -> NAME {,NAME} IN explist forbody */
- FuncState *fs = ls->fs;
- expdesc e;
- int nvars = 4; /* gen, state, control, plus at least one declared var */
- int line;
- int base = fs->freereg;
- /* create control variables */
- new_localvarliteral(ls, "(for generator)");
- new_localvarliteral(ls, "(for state)");
- new_localvarliteral(ls, "(for control)");
- /* create declared variables */
- new_localvar(ls, indexname);
- while (testnext(ls, ',')) {
- new_localvar(ls, str_checkname(ls));
- nvars++;
- }
- checknext(ls, TK_IN);
- line = ls->linenumber;
- adjust_assign(ls, 3, explist(ls, &e), &e);
- luaK_checkstack(fs, 3); /* extra space to call generator */
- forbody(ls, base, line, nvars - 3, 0);
+ /* forlist -> NAME {,NAME} IN explist forbody */
+ FuncState *fs = ls->fs;
+ expdesc e;
+ int nvars = 4; /* gen, state, control, plus at least one declared var */
+ int line;
+ int base = fs->freereg;
+ /* create control variables */
+ new_localvarliteral(ls, "(for generator)");
+ new_localvarliteral(ls, "(for state)");
+ new_localvarliteral(ls, "(for control)");
+ /* create declared variables */
+ new_localvar(ls, indexname);
+ while (testnext(ls, ',')) {
+ new_localvar(ls, str_checkname(ls));
+ nvars++;
+ }
+ checknext(ls, TK_IN);
+ line = ls->linenumber;
+ adjust_assign(ls, 3, explist(ls, &e), &e);
+ luaK_checkstack(fs, 3); /* extra space to call generator */
+ forbody(ls, base, line, nvars - 3, 0);
}
static void forstat (LexState *ls, int line) {
- /* forstat -> FOR (fornum | forlist) END */
- FuncState *fs = ls->fs;
- TString *varname;
- BlockCnt bl;
- enterblock(fs, &bl, 1); /* scope for loop and control variables */
- luaX_next(ls); /* skip `for' */
- varname = str_checkname(ls); /* first variable name */
- switch (ls->t.token) {
- case '=': fornum(ls, varname, line); break;
- case ',': case TK_IN: forlist(ls, varname); break;
- default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
- }
- check_match(ls, TK_END, TK_FOR, line);
- leaveblock(fs); /* loop scope (`break' jumps to this point) */
+ /* forstat -> FOR (fornum | forlist) END */
+ FuncState *fs = ls->fs;
+ TString *varname;
+ BlockCnt bl;
+ enterblock(fs, &bl, 1); /* scope for loop and control variables */
+ luaX_next(ls); /* skip `for' */
+ varname = str_checkname(ls); /* first variable name */
+ switch (ls->t.token) {
+ case '=': fornum(ls, varname, line); break;
+ case ',': case TK_IN: forlist(ls, varname); break;
+ default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
+ }
+ check_match(ls, TK_END, TK_FOR, line);
+ leaveblock(fs); /* loop scope (`break' jumps to this point) */
}
static void test_then_block (LexState *ls, int *escapelist) {
- /* test_then_block -> [IF | ELSEIF] cond THEN block */
- BlockCnt bl;
- FuncState *fs = ls->fs;
- expdesc v;
- int jf; /* instruction to skip 'then' code (if condition is false) */
- luaX_next(ls); /* skip IF or ELSEIF */
- expr(ls, &v); /* read condition */
- checknext(ls, TK_THEN);
- if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
- luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
- enterblock(fs, &bl, 0); /* must enter block before 'goto' */
- gotostat(ls, v.t); /* handle goto/break */
- skipnoopstat(ls); /* skip other no-op statements */
- if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
- leaveblock(fs);
- return; /* and that is it */
- }
- else /* must skip over 'then' part if condition is false */
- jf = luaK_jump(fs);
- }
- else { /* regular case (not goto/break) */
- luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
- enterblock(fs, &bl, 0);
- jf = v.f;
- }
- statlist(ls); /* `then' part */
- leaveblock(fs);
- if (ls->t.token == TK_ELSE ||
- ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
- luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
- luaK_patchtohere(fs, jf);
+ /* test_then_block -> [IF | ELSEIF] cond THEN block */
+ BlockCnt bl;
+ FuncState *fs = ls->fs;
+ expdesc v;
+ int jf; /* instruction to skip 'then' code (if condition is false) */
+ luaX_next(ls); /* skip IF or ELSEIF */
+ expr(ls, &v); /* read condition */
+ checknext(ls, TK_THEN);
+ if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
+ luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
+ enterblock(fs, &bl, 0); /* must enter block before 'goto' */
+ gotostat(ls, v.t); /* handle goto/break */
+ skipnoopstat(ls); /* skip other no-op statements */
+ if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
+ leaveblock(fs);
+ return; /* and that is it */
+ }
+ else /* must skip over 'then' part if condition is false */
+ jf = luaK_jump(fs);
+ }
+ else { /* regular case (not goto/break) */
+ luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
+ enterblock(fs, &bl, 0);
+ jf = v.f;
+ }
+ statlist(ls); /* `then' part */
+ leaveblock(fs);
+ if (ls->t.token == TK_ELSE ||
+ ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
+ luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
+ luaK_patchtohere(fs, jf);
}
static void ifstat (LexState *ls, int line) {
- /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
- FuncState *fs = ls->fs;
- int escapelist = NO_JUMP; /* exit list for finished parts */
- test_then_block(ls, &escapelist); /* IF cond THEN block */
- while (ls->t.token == TK_ELSEIF)
- test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
- if (testnext(ls, TK_ELSE))
- block(ls); /* `else' part */
- check_match(ls, TK_END, TK_IF, line);
- luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
+ /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
+ FuncState *fs = ls->fs;
+ int escapelist = NO_JUMP; /* exit list for finished parts */
+ test_then_block(ls, &escapelist); /* IF cond THEN block */
+ while (ls->t.token == TK_ELSEIF)
+ test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
+ if (testnext(ls, TK_ELSE))
+ block(ls); /* `else' part */
+ check_match(ls, TK_END, TK_IF, line);
+ luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
}
static void localfunc (LexState *ls) {
- expdesc b;
- FuncState *fs = ls->fs;
- new_localvar(ls, str_checkname(ls)); /* new local variable */
- adjustlocalvars(ls, 1); /* enter its scope */
- body(ls, &b, 0, ls->linenumber); /* function created in next register */
- /* debug information will only see the variable after this point! */
- getlocvar(fs, b.u.info)->startpc = fs->pc;
+ expdesc b;
+ FuncState *fs = ls->fs;
+ new_localvar(ls, str_checkname(ls)); /* new local variable */
+ adjustlocalvars(ls, 1); /* enter its scope */
+ body(ls, &b, 0, ls->linenumber); /* function created in next register */
+ /* debug information will only see the variable after this point! */
+ getlocvar(fs, b.u.info)->startpc = fs->pc;
}
static void localstat (LexState *ls) {
- /* stat -> LOCAL NAME {`,' NAME} [`=' explist] */
- int nvars = 0;
- int nexps;
- expdesc e;
- do {
- new_localvar(ls, str_checkname(ls));
- nvars++;
- } while (testnext(ls, ','));
- if (testnext(ls, '='))
- nexps = explist(ls, &e);
- else {
- e.k = VVOID;
- nexps = 0;
- }
- adjust_assign(ls, nvars, nexps, &e);
- adjustlocalvars(ls, nvars);
+ /* stat -> LOCAL NAME {`,' NAME} [`=' explist] */
+ int nvars = 0;
+ int nexps;
+ expdesc e;
+ do {
+ new_localvar(ls, str_checkname(ls));
+ nvars++;
+ } while (testnext(ls, ','));
+ if (testnext(ls, '='))
+ nexps = explist(ls, &e);
+ else {
+ e.k = VVOID;
+ nexps = 0;
+ }
+ adjust_assign(ls, nvars, nexps, &e);
+ adjustlocalvars(ls, nvars);
}
static int funcname (LexState *ls, expdesc *v) {
- /* funcname -> NAME {fieldsel} [`:' NAME] */
- int ismethod = 0;
- singlevar(ls, v);
- while (ls->t.token == '.')
- fieldsel(ls, v);
- if (ls->t.token == ':') {
- ismethod = 1;
- fieldsel(ls, v);
- }
- return ismethod;
+ /* funcname -> NAME {fieldsel} [`:' NAME] */
+ int ismethod = 0;
+ singlevar(ls, v);
+ while (ls->t.token == '.')
+ fieldsel(ls, v);
+ if (ls->t.token == ':') {
+ ismethod = 1;
+ fieldsel(ls, v);
+ }
+ return ismethod;
}
static void funcstat (LexState *ls, int line) {
- /* funcstat -> FUNCTION funcname body */
- int ismethod;
- expdesc v, b;
- luaX_next(ls); /* skip FUNCTION */
- ismethod = funcname(ls, &v);
- body(ls, &b, ismethod, line);
- luaK_storevar(ls->fs, &v, &b);
- luaK_fixline(ls->fs, line); /* definition `happens' in the first line */
+ /* funcstat -> FUNCTION funcname body */
+ int ismethod;
+ expdesc v, b;
+ luaX_next(ls); /* skip FUNCTION */
+ ismethod = funcname(ls, &v);
+ body(ls, &b, ismethod, line);
+ luaK_storevar(ls->fs, &v, &b);
+ luaK_fixline(ls->fs, line); /* definition `happens' in the first line */
}
static void exprstat (LexState *ls) {
- /* stat -> func | assignment */
- FuncState *fs = ls->fs;
- struct LHS_assign v;
- suffixedexp(ls, &v.v);
- if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
- v.prev = NULL;
- assignment(ls, &v, 1);
- }
- else { /* stat -> func */
- check_condition(ls, v.v.k == VCALL, "syntax error");
- SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
- }
+ /* stat -> func | assignment */
+ FuncState *fs = ls->fs;
+ struct LHS_assign v;
+ suffixedexp(ls, &v.v);
+ if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
+ v.prev = NULL;
+ assignment(ls, &v, 1);
+ }
+ else { /* stat -> func */
+ check_condition(ls, v.v.k == VCALL, "syntax error");
+ SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
+ }
}
static void retstat (LexState *ls) {
- /* stat -> RETURN [explist] [';'] */
- FuncState *fs = ls->fs;
- expdesc e;
- int first, nret; /* registers with returned values */
- if (block_follow(ls, 1) || ls->t.token == ';')
- first = nret = 0; /* return no values */
- else {
- nret = explist(ls, &e); /* optional return values */
- if (hasmultret(e.k)) {
- luaK_setmultret(fs, &e);
- if (e.k == VCALL && nret == 1) { /* tail call? */
- SET_OPCODE(getcode(fs,&e), OP_TAILCALL);
- lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
- }
- first = fs->nactvar;
- nret = LUA_MULTRET; /* return all values */
- }
- else {
- if (nret == 1) /* only one single value? */
- first = luaK_exp2anyreg(fs, &e);
- else {
- luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
- first = fs->nactvar; /* return all `active' values */
- lua_assert(nret == fs->freereg - first);
- }
- }
- }
- luaK_ret(fs, first, nret);
- testnext(ls, ';'); /* skip optional semicolon */
+ /* stat -> RETURN [explist] [';'] */
+ FuncState *fs = ls->fs;
+ expdesc e;
+ int first, nret; /* registers with returned values */
+ if (block_follow(ls, 1) || ls->t.token == ';')
+ first = nret = 0; /* return no values */
+ else {
+ nret = explist(ls, &e); /* optional return values */
+ if (hasmultret(e.k)) {
+ luaK_setmultret(fs, &e);
+ if (e.k == VCALL && nret == 1) { /* tail call? */
+ SET_OPCODE(getcode(fs,&e), OP_TAILCALL);
+ lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
+ }
+ first = fs->nactvar;
+ nret = LUA_MULTRET; /* return all values */
+ }
+ else {
+ if (nret == 1) /* only one single value? */
+ first = luaK_exp2anyreg(fs, &e);
+ else {
+ luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
+ first = fs->nactvar; /* return all `active' values */
+ lua_assert(nret == fs->freereg - first);
+ }
+ }
+ }
+ luaK_ret(fs, first, nret);
+ testnext(ls, ';'); /* skip optional semicolon */
}
static void statement (LexState *ls) {
- int line = ls->linenumber; /* may be needed for error messages */
- enterlevel(ls);
- switch (ls->t.token) {
- case ';': { /* stat -> ';' (empty statement) */
- luaX_next(ls); /* skip ';' */
- break;
- }
- case TK_IF: { /* stat -> ifstat */
- ifstat(ls, line);
- break;
- }
- case TK_WHILE: { /* stat -> whilestat */
- whilestat(ls, line);
- break;
- }
- case TK_DO: { /* stat -> DO block END */
- luaX_next(ls); /* skip DO */
- block(ls);
- check_match(ls, TK_END, TK_DO, line);
- break;
- }
- case TK_FOR: { /* stat -> forstat */
- forstat(ls, line);
- break;
- }
- case TK_REPEAT: { /* stat -> repeatstat */
- repeatstat(ls, line);
- break;
- }
- case TK_FUNCTION: { /* stat -> funcstat */
- funcstat(ls, line);
- break;
- }
- case TK_LOCAL: { /* stat -> localstat */
- luaX_next(ls); /* skip LOCAL */
- if (testnext(ls, TK_FUNCTION)) /* local function? */
- localfunc(ls);
- else
- localstat(ls);
- break;
- }
- case TK_DBCOLON: { /* stat -> label */
- luaX_next(ls); /* skip double colon */
- labelstat(ls, str_checkname(ls), line);
- break;
- }
- case TK_RETURN: { /* stat -> retstat */
- luaX_next(ls); /* skip RETURN */
- retstat(ls);
- break;
- }
- case TK_BREAK: /* stat -> breakstat */
- case TK_GOTO: { /* stat -> 'goto' NAME */
- gotostat(ls, luaK_jump(ls->fs));
- break;
- }
- default: { /* stat -> func | assignment */
- exprstat(ls);
- break;
- }
- }
- lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
- ls->fs->freereg >= ls->fs->nactvar);
- ls->fs->freereg = ls->fs->nactvar; /* free registers */
- leavelevel(ls);
+ int line = ls->linenumber; /* may be needed for error messages */
+ enterlevel(ls);
+ switch (ls->t.token) {
+ case ';': { /* stat -> ';' (empty statement) */
+ luaX_next(ls); /* skip ';' */
+ break;
+ }
+ case TK_IF: { /* stat -> ifstat */
+ ifstat(ls, line);
+ break;
+ }
+ case TK_WHILE: { /* stat -> whilestat */
+ whilestat(ls, line);
+ break;
+ }
+ case TK_DO: { /* stat -> DO block END */
+ luaX_next(ls); /* skip DO */
+ block(ls);
+ check_match(ls, TK_END, TK_DO, line);
+ break;
+ }
+ case TK_FOR: { /* stat -> forstat */
+ forstat(ls, line);
+ break;
+ }
+ case TK_REPEAT: { /* stat -> repeatstat */
+ repeatstat(ls, line);
+ break;
+ }
+ case TK_FUNCTION: { /* stat -> funcstat */
+ funcstat(ls, line);
+ break;
+ }
+ case TK_LOCAL: { /* stat -> localstat */
+ luaX_next(ls); /* skip LOCAL */
+ if (testnext(ls, TK_FUNCTION)) /* local function? */
+ localfunc(ls);
+ else
+ localstat(ls);
+ break;
+ }
+ case TK_DBCOLON: { /* stat -> label */
+ luaX_next(ls); /* skip double colon */
+ labelstat(ls, str_checkname(ls), line);
+ break;
+ }
+ case TK_RETURN: { /* stat -> retstat */
+ luaX_next(ls); /* skip RETURN */
+ retstat(ls);
+ break;
+ }
+ case TK_BREAK: /* stat -> breakstat */
+ case TK_GOTO: { /* stat -> 'goto' NAME */
+ gotostat(ls, luaK_jump(ls->fs));
+ break;
+ }
+ default: { /* stat -> func | assignment */
+ exprstat(ls);
+ break;
+ }
+ }
+ lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
+ ls->fs->freereg >= ls->fs->nactvar);
+ ls->fs->freereg = ls->fs->nactvar; /* free registers */
+ leavelevel(ls);
}
/* }====================================================================== */
@@ -1602,37 +1602,36 @@ static void statement (LexState *ls) {
** upvalue named LUA_ENV
*/
static void mainfunc (LexState *ls, FuncState *fs) {
- BlockCnt bl;
- expdesc v;
- open_func(ls, fs, &bl);
- fs->f->is_vararg = 1; /* main function is always vararg */
- init_exp(&v, VLOCAL, 0); /* create and... */
- newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
- luaX_next(ls); /* read first token */
- statlist(ls); /* parse main body */
- check(ls, TK_EOS);
- close_func(ls);
+ BlockCnt bl;
+ expdesc v;
+ open_func(ls, fs, &bl);
+ fs->f->is_vararg = 1; /* main function is always vararg */
+ init_exp(&v, VLOCAL, 0); /* create and... */
+ newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
+ luaX_next(ls); /* read first token */
+ statlist(ls); /* parse main body */
+ check(ls, TK_EOS);
+ close_func(ls);
}
Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
- Dyndata *dyd, const char *name, int firstchar) {
- LexState lexstate;
- FuncState funcstate;
- Closure *cl = luaF_newLclosure(L, 1); /* create main closure */
- /* anchor closure (to avoid being collected) */
- setclLvalue(L, L->top, cl);
- incr_top(L);
- funcstate.f = cl->l.p = luaF_newproto(L);
- funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
- lexstate.buff = buff;
- lexstate.dyd = dyd;
- dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
- luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
- mainfunc(&lexstate, &funcstate);
- lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
- /* all scopes should be correctly finished */
- lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
- return cl; /* it's on the stack too */
+ Dyndata *dyd, const char *name, int firstchar) {
+ LexState lexstate;
+ FuncState funcstate;
+ Closure *cl = luaF_newLclosure(L, 1); /* create main closure */
+ /* anchor closure (to avoid being collected) */
+ setclLvalue(L, L->top, cl);
+ incr_top(L);
+ funcstate.f = cl->l.p = luaF_newproto(L);
+ funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
+ lexstate.buff = buff;
+ lexstate.dyd = dyd;
+ dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
+ luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
+ mainfunc(&lexstate, &funcstate);
+ lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
+ /* all scopes should be correctly finished */
+ lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
+ return cl; /* it's on the stack too */
}
-
diff --git a/src/lib/lua/lparser.h b/src/lib/lua/lparser.h
index 301167d4f5c..d64b5c61f48 100644
--- a/src/lib/lua/lparser.h
+++ b/src/lib/lua/lparser.h
@@ -17,74 +17,74 @@
*/
typedef enum {
- VVOID, /* no value */
- VNIL,
- VTRUE,
- VFALSE,
- VK, /* info = index of constant in `k' */
- VKNUM, /* nval = numerical value */
- VNONRELOC, /* info = result register */
- VLOCAL, /* info = local register */
- VUPVAL, /* info = index of upvalue in 'upvalues' */
- VINDEXED, /* t = table register/upvalue; idx = index R/K */
- VJMP, /* info = instruction pc */
- VRELOCABLE, /* info = instruction pc */
- VCALL, /* info = instruction pc */
- VVARARG /* info = instruction pc */
+ VVOID, /* no value */
+ VNIL,
+ VTRUE,
+ VFALSE,
+ VK, /* info = index of constant in `k' */
+ VKNUM, /* nval = numerical value */
+ VNONRELOC, /* info = result register */
+ VLOCAL, /* info = local register */
+ VUPVAL, /* info = index of upvalue in 'upvalues' */
+ VINDEXED, /* t = table register/upvalue; idx = index R/K */
+ VJMP, /* info = instruction pc */
+ VRELOCABLE, /* info = instruction pc */
+ VCALL, /* info = instruction pc */
+ VVARARG /* info = instruction pc */
} expkind;
-#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
-#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
+#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
+#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
typedef struct expdesc {
- expkind k;
- union {
- struct { /* for indexed variables (VINDEXED) */
- short idx; /* index (R/K) */
- lu_byte t; /* table (register or upvalue) */
- lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
- } ind;
- int info; /* for generic use */
- lua_Number nval; /* for VKNUM */
- } u;
- int t; /* patch list of `exit when true' */
- int f; /* patch list of `exit when false' */
+ expkind k;
+ union {
+ struct { /* for indexed variables (VINDEXED) */
+ short idx; /* index (R/K) */
+ lu_byte t; /* table (register or upvalue) */
+ lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
+ } ind;
+ int info; /* for generic use */
+ lua_Number nval; /* for VKNUM */
+ } u;
+ int t; /* patch list of `exit when true' */
+ int f; /* patch list of `exit when false' */
} expdesc;
/* description of active local variable */
typedef struct Vardesc {
- short idx; /* variable index in stack */
+ short idx; /* variable index in stack */
} Vardesc;
/* description of pending goto statements and label statements */
typedef struct Labeldesc {
- TString *name; /* label identifier */
- int pc; /* position in code */
- int line; /* line where it appeared */
- lu_byte nactvar; /* local level where it appears in current block */
+ TString *name; /* label identifier */
+ int pc; /* position in code */
+ int line; /* line where it appeared */
+ lu_byte nactvar; /* local level where it appears in current block */
} Labeldesc;
/* list of labels or gotos */
typedef struct Labellist {
- Labeldesc *arr; /* array */
- int n; /* number of entries in use */
- int size; /* array size */
+ Labeldesc *arr; /* array */
+ int n; /* number of entries in use */
+ int size; /* array size */
} Labellist;
/* dynamic structures used by the parser */
typedef struct Dyndata {
- struct { /* list of active local variables */
- Vardesc *arr;
- int n;
- int size;
- } actvar;
- Labellist gt; /* list of pending gotos */
- Labellist label; /* list of active labels */
+ struct { /* list of active local variables */
+ Vardesc *arr;
+ int n;
+ int size;
+ } actvar;
+ Labellist gt; /* list of pending gotos */
+ Labellist label; /* list of active labels */
} Dyndata;
@@ -94,26 +94,26 @@ struct BlockCnt; /* defined in lparser.c */
/* state needed to generate code for a given function */
typedef struct FuncState {
- Proto *f; /* current function header */
- Table *h; /* table to find (and reuse) elements in `k' */
- struct FuncState *prev; /* enclosing function */
- struct LexState *ls; /* lexical state */
- struct BlockCnt *bl; /* chain of current blocks */
- int pc; /* next position to code (equivalent to `ncode') */
- int lasttarget; /* 'label' of last 'jump label' */
- int jpc; /* list of pending jumps to `pc' */
- int nk; /* number of elements in `k' */
- int np; /* number of elements in `p' */
- int firstlocal; /* index of first local var (in Dyndata array) */
- short nlocvars; /* number of elements in 'f->locvars' */
- lu_byte nactvar; /* number of active local variables */
- lu_byte nups; /* number of upvalues */
- lu_byte freereg; /* first free register */
+ Proto *f; /* current function header */
+ Table *h; /* table to find (and reuse) elements in `k' */
+ struct FuncState *prev; /* enclosing function */
+ struct LexState *ls; /* lexical state */
+ struct BlockCnt *bl; /* chain of current blocks */
+ int pc; /* next position to code (equivalent to `ncode') */
+ int lasttarget; /* 'label' of last 'jump label' */
+ int jpc; /* list of pending jumps to `pc' */
+ int nk; /* number of elements in `k' */
+ int np; /* number of elements in `p' */
+ int firstlocal; /* index of first local var (in Dyndata array) */
+ short nlocvars; /* number of elements in 'f->locvars' */
+ lu_byte nactvar; /* number of active local variables */
+ lu_byte nups; /* number of upvalues */
+ lu_byte freereg; /* first free register */
} FuncState;
LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
- Dyndata *dyd, const char *name, int firstchar);
+ Dyndata *dyd, const char *name, int firstchar);
#endif
diff --git a/src/lib/lua/lstate.c b/src/lib/lua/lstate.c
index 207a106d5ba..d75caadfeb0 100644
--- a/src/lib/lua/lstate.c
+++ b/src/lib/lua/lstate.c
@@ -27,19 +27,19 @@
#if !defined(LUAI_GCPAUSE)
-#define LUAI_GCPAUSE 200 /* 200% */
+#define LUAI_GCPAUSE 200 /* 200% */
#endif
#if !defined(LUAI_GCMAJOR)
-#define LUAI_GCMAJOR 200 /* 200% */
+#define LUAI_GCMAJOR 200 /* 200% */
#endif
#if !defined(LUAI_GCMUL)
-#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
+#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
#endif
-#define MEMERRMSG "not enough memory"
+#define MEMERRMSG "not enough memory"
/*
@@ -48,7 +48,7 @@
*/
#if !defined(luai_makeseed)
#include <time.h>
-#define luai_makeseed() cast(unsigned int, time(NULL))
+#define luai_makeseed() cast(unsigned int, time(NULL))
#endif
@@ -58,9 +58,9 @@
*/
typedef struct LX {
#if defined(LUAI_EXTRASPACE)
- char buff[LUAI_EXTRASPACE];
+ char buff[LUAI_EXTRASPACE];
#endif
- lua_State l;
+ lua_State l;
} LX;
@@ -68,13 +68,13 @@ typedef struct LX {
** Main thread combines a thread state and the global state
*/
typedef struct LG {
- LX l;
- global_State g;
+ LX l;
+ global_State g;
} LG;
-#define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))
+#define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))
/*
@@ -83,19 +83,19 @@ typedef struct LG {
** randomness..
*/
#define addbuff(b,p,e) \
- { size_t t = cast(size_t, e); \
- memcpy(buff + p, &t, sizeof(t)); p += sizeof(t); }
+ { size_t t = cast(size_t, e); \
+ memcpy(buff + p, &t, sizeof(t)); p += sizeof(t); }
static unsigned int makeseed (lua_State *L) {
- char buff[4 * sizeof(size_t)];
- unsigned int h = luai_makeseed();
- int p = 0;
- addbuff(buff, p, L); /* heap variable */
- addbuff(buff, p, &h); /* local variable */
- addbuff(buff, p, luaO_nilobject); /* global variable */
- addbuff(buff, p, &lua_newstate); /* public function */
- lua_assert(p == sizeof(buff));
- return luaS_hash(buff, p, h);
+ char buff[4 * sizeof(size_t)];
+ unsigned int h = luai_makeseed();
+ int p = 0;
+ addbuff(buff, p, L); /* heap variable */
+ addbuff(buff, p, &h); /* local variable */
+ addbuff(buff, p, luaO_nilobject); /* global variable */
+ addbuff(buff, p, &lua_newstate); /* public function */
+ lua_assert(p == sizeof(buff));
+ return luaS_hash(buff, p, h);
}
@@ -104,58 +104,58 @@ static unsigned int makeseed (lua_State *L) {
** invariant
*/
void luaE_setdebt (global_State *g, l_mem debt) {
- g->totalbytes -= (debt - g->GCdebt);
- g->GCdebt = debt;
+ g->totalbytes -= (debt - g->GCdebt);
+ g->GCdebt = debt;
}
CallInfo *luaE_extendCI (lua_State *L) {
- CallInfo *ci = luaM_new(L, CallInfo);
- lua_assert(L->ci->next == NULL);
- L->ci->next = ci;
- ci->previous = L->ci;
- ci->next = NULL;
- return ci;
+ CallInfo *ci = luaM_new(L, CallInfo);
+ lua_assert(L->ci->next == NULL);
+ L->ci->next = ci;
+ ci->previous = L->ci;
+ ci->next = NULL;
+ return ci;
}
void luaE_freeCI (lua_State *L) {
- CallInfo *ci = L->ci;
- CallInfo *next = ci->next;
- ci->next = NULL;
- while ((ci = next) != NULL) {
- next = ci->next;
- luaM_free(L, ci);
- }
+ CallInfo *ci = L->ci;
+ CallInfo *next = ci->next;
+ ci->next = NULL;
+ while ((ci = next) != NULL) {
+ next = ci->next;
+ luaM_free(L, ci);
+ }
}
static void stack_init (lua_State *L1, lua_State *L) {
- int i; CallInfo *ci;
- /* initialize stack array */
- L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);
- L1->stacksize = BASIC_STACK_SIZE;
- for (i = 0; i < BASIC_STACK_SIZE; i++)
- setnilvalue(L1->stack + i); /* erase new stack */
- L1->top = L1->stack;
- L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;
- /* initialize first ci */
- ci = &L1->base_ci;
- ci->next = ci->previous = NULL;
- ci->callstatus = 0;
- ci->func = L1->top;
- setnilvalue(L1->top++); /* 'function' entry for this 'ci' */
- ci->top = L1->top + LUA_MINSTACK;
- L1->ci = ci;
+ int i; CallInfo *ci;
+ /* initialize stack array */
+ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);
+ L1->stacksize = BASIC_STACK_SIZE;
+ for (i = 0; i < BASIC_STACK_SIZE; i++)
+ setnilvalue(L1->stack + i); /* erase new stack */
+ L1->top = L1->stack;
+ L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;
+ /* initialize first ci */
+ ci = &L1->base_ci;
+ ci->next = ci->previous = NULL;
+ ci->callstatus = 0;
+ ci->func = L1->top;
+ setnilvalue(L1->top++); /* 'function' entry for this 'ci' */
+ ci->top = L1->top + LUA_MINSTACK;
+ L1->ci = ci;
}
static void freestack (lua_State *L) {
- if (L->stack == NULL)
- return; /* stack not completely built yet */
- L->ci = &L->base_ci; /* free the entire 'ci' list */
- luaE_freeCI(L);
- luaM_freearray(L, L->stack, L->stacksize); /* free stack array */
+ if (L->stack == NULL)
+ return; /* stack not completely built yet */
+ L->ci = &L->base_ci; /* free the entire 'ci' list */
+ luaE_freeCI(L);
+ luaM_freearray(L, L->stack, L->stacksize); /* free stack array */
}
@@ -163,17 +163,17 @@ static void freestack (lua_State *L) {
** Create registry table and its predefined values
*/
static void init_registry (lua_State *L, global_State *g) {
- TValue mt;
- /* create registry */
- Table *registry = luaH_new(L);
- sethvalue(L, &g->l_registry, registry);
- luaH_resize(L, registry, LUA_RIDX_LAST, 0);
- /* registry[LUA_RIDX_MAINTHREAD] = L */
- setthvalue(L, &mt, L);
- luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt);
- /* registry[LUA_RIDX_GLOBALS] = table of globals */
- sethvalue(L, &mt, luaH_new(L));
- luaH_setint(L, registry, LUA_RIDX_GLOBALS, &mt);
+ TValue mt;
+ /* create registry */
+ Table *registry = luaH_new(L);
+ sethvalue(L, &g->l_registry, registry);
+ luaH_resize(L, registry, LUA_RIDX_LAST, 0);
+ /* registry[LUA_RIDX_MAINTHREAD] = L */
+ setthvalue(L, &mt, L);
+ luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt);
+ /* registry[LUA_RIDX_GLOBALS] = table of globals */
+ sethvalue(L, &mt, luaH_new(L));
+ luaH_setint(L, registry, LUA_RIDX_GLOBALS, &mt);
}
@@ -181,17 +181,17 @@ static void init_registry (lua_State *L, global_State *g) {
** open parts of the state that may cause memory-allocation errors
*/
static void f_luaopen (lua_State *L, void *ud) {
- global_State *g = G(L);
- UNUSED(ud);
- stack_init(L, L); /* init stack */
- init_registry(L, g);
- luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
- luaT_init(L);
- luaX_init(L);
- /* pre-create memory-error message */
- g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
- luaS_fix(g->memerrmsg); /* it should never be collected */
- g->gcrunning = 1; /* allow gc */
+ global_State *g = G(L);
+ UNUSED(ud);
+ stack_init(L, L); /* init stack */
+ init_registry(L, g);
+ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
+ luaT_init(L);
+ luaX_init(L);
+ /* pre-create memory-error message */
+ g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
+ luaS_fix(g->memerrmsg); /* it should never be collected */
+ g->gcrunning = 1; /* allow gc */
}
@@ -200,123 +200,121 @@ static void f_luaopen (lua_State *L, void *ud) {
** any memory (to avoid errors)
*/
static void preinit_state (lua_State *L, global_State *g) {
- G(L) = g;
- L->stack = NULL;
- L->ci = NULL;
- L->stacksize = 0;
- L->errorJmp = NULL;
- L->nCcalls = 0;
- L->hook = NULL;
- L->hookmask = 0;
- L->basehookcount = 0;
- L->allowhook = 1;
- resethookcount(L);
- L->openupval = NULL;
- L->nny = 1;
- L->status = LUA_OK;
- L->errfunc = 0;
+ G(L) = g;
+ L->stack = NULL;
+ L->ci = NULL;
+ L->stacksize = 0;
+ L->errorJmp = NULL;
+ L->nCcalls = 0;
+ L->hook = NULL;
+ L->hookmask = 0;
+ L->basehookcount = 0;
+ L->allowhook = 1;
+ resethookcount(L);
+ L->openupval = NULL;
+ L->nny = 1;
+ L->status = LUA_OK;
+ L->errfunc = 0;
}
static void close_state (lua_State *L) {
- global_State *g = G(L);
- luaF_close(L, L->stack); /* close all upvalues for this thread */
- luaC_freeallobjects(L); /* collect all objects */
- luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
- luaZ_freebuffer(L, &g->buff);
- freestack(L);
- lua_assert(gettotalbytes(g) == sizeof(LG));
- (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
+ global_State *g = G(L);
+ luaF_close(L, L->stack); /* close all upvalues for this thread */
+ luaC_freeallobjects(L); /* collect all objects */
+ luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
+ luaZ_freebuffer(L, &g->buff);
+ freestack(L);
+ lua_assert(gettotalbytes(g) == sizeof(LG));
+ (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
}
LUA_API lua_State *lua_newthread (lua_State *L) {
- lua_State *L1;
- lua_lock(L);
- luaC_checkGC(L);
- L1 = &luaC_newobj(L, LUA_TTHREAD, sizeof(LX), NULL, offsetof(LX, l))->th;
- setthvalue(L, L->top, L1);
- api_incr_top(L);
- preinit_state(L1, G(L));
- L1->hookmask = L->hookmask;
- L1->basehookcount = L->basehookcount;
- L1->hook = L->hook;
- resethookcount(L1);
- luai_userstatethread(L, L1);
- stack_init(L1, L); /* init stack */
- lua_unlock(L);
- return L1;
+ lua_State *L1;
+ lua_lock(L);
+ luaC_checkGC(L);
+ L1 = &luaC_newobj(L, LUA_TTHREAD, sizeof(LX), NULL, offsetof(LX, l))->th;
+ setthvalue(L, L->top, L1);
+ api_incr_top(L);
+ preinit_state(L1, G(L));
+ L1->hookmask = L->hookmask;
+ L1->basehookcount = L->basehookcount;
+ L1->hook = L->hook;
+ resethookcount(L1);
+ luai_userstatethread(L, L1);
+ stack_init(L1, L); /* init stack */
+ lua_unlock(L);
+ return L1;
}
void luaE_freethread (lua_State *L, lua_State *L1) {
- LX *l = fromstate(L1);
- luaF_close(L1, L1->stack); /* close all upvalues for this thread */
- lua_assert(L1->openupval == NULL);
- luai_userstatefree(L, L1);
- freestack(L1);
- luaM_free(L, l);
+ LX *l = fromstate(L1);
+ luaF_close(L1, L1->stack); /* close all upvalues for this thread */
+ lua_assert(L1->openupval == NULL);
+ luai_userstatefree(L, L1);
+ freestack(L1);
+ luaM_free(L, l);
}
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
- int i;
- lua_State *L;
- global_State *g;
- LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));
- if (l == NULL) return NULL;
- L = &l->l.l;
- g = &l->g;
- L->next = NULL;
- L->tt = LUA_TTHREAD;
- g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
- L->marked = luaC_white(g);
- g->gckind = KGC_NORMAL;
- preinit_state(L, g);
- g->frealloc = f;
- g->ud = ud;
- g->mainthread = L;
- g->seed = makeseed(L);
- g->uvhead.u.l.prev = &g->uvhead;
- g->uvhead.u.l.next = &g->uvhead;
- g->gcrunning = 0; /* no GC while building state */
- g->GCestimate = 0;
- g->strt.size = 0;
- g->strt.nuse = 0;
- g->strt.hash = NULL;
- setnilvalue(&g->l_registry);
- luaZ_initbuffer(L, &g->buff);
- g->panic = NULL;
- g->version = lua_version(NULL);
- g->gcstate = GCSpause;
- g->allgc = NULL;
- g->finobj = NULL;
- g->tobefnz = NULL;
- g->sweepgc = g->sweepfin = NULL;
- g->gray = g->grayagain = NULL;
- g->weak = g->ephemeron = g->allweak = NULL;
- g->totalbytes = sizeof(LG);
- g->GCdebt = 0;
- g->gcpause = LUAI_GCPAUSE;
- g->gcmajorinc = LUAI_GCMAJOR;
- g->gcstepmul = LUAI_GCMUL;
- for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
- if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
- /* memory allocation error: free partial state */
- close_state(L);
- L = NULL;
- }
- else
- luai_userstateopen(L);
- return L;
+ int i;
+ lua_State *L;
+ global_State *g;
+ LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));
+ if (l == NULL) return NULL;
+ L = &l->l.l;
+ g = &l->g;
+ L->next = NULL;
+ L->tt = LUA_TTHREAD;
+ g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
+ L->marked = luaC_white(g);
+ g->gckind = KGC_NORMAL;
+ preinit_state(L, g);
+ g->frealloc = f;
+ g->ud = ud;
+ g->mainthread = L;
+ g->seed = makeseed(L);
+ g->uvhead.u.l.prev = &g->uvhead;
+ g->uvhead.u.l.next = &g->uvhead;
+ g->gcrunning = 0; /* no GC while building state */
+ g->GCestimate = 0;
+ g->strt.size = 0;
+ g->strt.nuse = 0;
+ g->strt.hash = NULL;
+ setnilvalue(&g->l_registry);
+ luaZ_initbuffer(L, &g->buff);
+ g->panic = NULL;
+ g->version = lua_version(NULL);
+ g->gcstate = GCSpause;
+ g->allgc = NULL;
+ g->finobj = NULL;
+ g->tobefnz = NULL;
+ g->sweepgc = g->sweepfin = NULL;
+ g->gray = g->grayagain = NULL;
+ g->weak = g->ephemeron = g->allweak = NULL;
+ g->totalbytes = sizeof(LG);
+ g->GCdebt = 0;
+ g->gcpause = LUAI_GCPAUSE;
+ g->gcmajorinc = LUAI_GCMAJOR;
+ g->gcstepmul = LUAI_GCMUL;
+ for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
+ if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
+ /* memory allocation error: free partial state */
+ close_state(L);
+ L = NULL;
+ }
+ else
+ luai_userstateopen(L);
+ return L;
}
LUA_API void lua_close (lua_State *L) {
- L = G(L)->mainthread; /* only the main thread can be closed */
- lua_lock(L);
- luai_userstateclose(L);
- close_state(L);
+ L = G(L)->mainthread; /* only the main thread can be closed */
+ lua_lock(L);
+ luai_userstateclose(L);
+ close_state(L);
}
-
-
diff --git a/src/lib/lua/lstate.h b/src/lib/lua/lstate.h
index c8a31f5c0b8..706ea274f76 100644
--- a/src/lib/lua/lstate.h
+++ b/src/lib/lua/lstate.h
@@ -51,15 +51,15 @@ struct lua_longjmp; /* defined in ldo.c */
/* kinds of Garbage Collection */
-#define KGC_NORMAL 0
-#define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */
-#define KGC_GEN 2 /* generational collection */
+#define KGC_NORMAL 0
+#define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */
+#define KGC_GEN 2 /* generational collection */
typedef struct stringtable {
- GCObject **hash;
- lu_int32 nuse; /* number of elements */
- int size;
+ GCObject **hash;
+ lu_int32 nuse; /* number of elements */
+ int size;
} stringtable;
@@ -67,84 +67,84 @@ typedef struct stringtable {
** information about a call
*/
typedef struct CallInfo {
- StkId func; /* function index in the stack */
- StkId top; /* top for this function */
- struct CallInfo *previous, *next; /* dynamic call link */
- short nresults; /* expected number of results from this function */
- lu_byte callstatus;
- ptrdiff_t extra;
- union {
- struct { /* only for Lua functions */
- StkId base; /* base for this function */
- const Instruction *savedpc;
- } l;
- struct { /* only for C functions */
- int ctx; /* context info. in case of yields */
- lua_CFunction k; /* continuation in case of yields */
- ptrdiff_t old_errfunc;
- lu_byte old_allowhook;
- lu_byte status;
- } c;
- } u;
+ StkId func; /* function index in the stack */
+ StkId top; /* top for this function */
+ struct CallInfo *previous, *next; /* dynamic call link */
+ short nresults; /* expected number of results from this function */
+ lu_byte callstatus;
+ ptrdiff_t extra;
+ union {
+ struct { /* only for Lua functions */
+ StkId base; /* base for this function */
+ const Instruction *savedpc;
+ } l;
+ struct { /* only for C functions */
+ int ctx; /* context info. in case of yields */
+ lua_CFunction k; /* continuation in case of yields */
+ ptrdiff_t old_errfunc;
+ lu_byte old_allowhook;
+ lu_byte status;
+ } c;
+ } u;
} CallInfo;
/*
** Bits in CallInfo status
*/
-#define CIST_LUA (1<<0) /* call is running a Lua function */
-#define CIST_HOOKED (1<<1) /* call is running a debug hook */
-#define CIST_REENTRY (1<<2) /* call is running on same invocation of
+#define CIST_LUA (1<<0) /* call is running a Lua function */
+#define CIST_HOOKED (1<<1) /* call is running a debug hook */
+#define CIST_REENTRY (1<<2) /* call is running on same invocation of
luaV_execute of previous call */
-#define CIST_YIELDED (1<<3) /* call reentered after suspension */
-#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
-#define CIST_STAT (1<<5) /* call has an error status (pcall) */
-#define CIST_TAIL (1<<6) /* call was tail called */
-#define CIST_HOOKYIELD (1<<7) /* last hook called yielded */
+#define CIST_YIELDED (1<<3) /* call reentered after suspension */
+#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
+#define CIST_STAT (1<<5) /* call has an error status (pcall) */
+#define CIST_TAIL (1<<6) /* call was tail called */
+#define CIST_HOOKYIELD (1<<7) /* last hook called yielded */
-#define isLua(ci) ((ci)->callstatus & CIST_LUA)
+#define isLua(ci) ((ci)->callstatus & CIST_LUA)
/*
** `global state', shared by all threads of this state
*/
typedef struct global_State {
- lua_Alloc frealloc; /* function to reallocate memory */
- void *ud; /* auxiliary data to `frealloc' */
- lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
- l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
- lu_mem GCmemtrav; /* memory traversed by the GC */
- lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
- stringtable strt; /* hash table for strings */
- TValue l_registry;
- unsigned int seed; /* randomized seed for hashes */
- lu_byte currentwhite;
- lu_byte gcstate; /* state of garbage collector */
- lu_byte gckind; /* kind of GC running */
- lu_byte gcrunning; /* true if GC is running */
- int sweepstrgc; /* position of sweep in `strt' */
- GCObject *allgc; /* list of all collectable objects */
- GCObject *finobj; /* list of collectable objects with finalizers */
- GCObject **sweepgc; /* current position of sweep in list 'allgc' */
- GCObject **sweepfin; /* current position of sweep in list 'finobj' */
- GCObject *gray; /* list of gray objects */
- GCObject *grayagain; /* list of objects to be traversed atomically */
- GCObject *weak; /* list of tables with weak values */
- GCObject *ephemeron; /* list of ephemeron tables (weak keys) */
- GCObject *allweak; /* list of all-weak tables */
- GCObject *tobefnz; /* list of userdata to be GC */
- UpVal uvhead; /* head of double-linked list of all open upvalues */
- Mbuffer buff; /* temporary buffer for string concatenation */
- int gcpause; /* size of pause between successive GCs */
- int gcmajorinc; /* pause between major collections (only in gen. mode) */
- int gcstepmul; /* GC `granularity' */
- lua_CFunction panic; /* to be called in unprotected errors */
- struct lua_State *mainthread;
- const lua_Number *version; /* pointer to version number */
- TString *memerrmsg; /* memory-error message */
- TString *tmname[TM_N]; /* array with tag-method names */
- struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
+ lua_Alloc frealloc; /* function to reallocate memory */
+ void *ud; /* auxiliary data to `frealloc' */
+ lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
+ l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
+ lu_mem GCmemtrav; /* memory traversed by the GC */
+ lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
+ stringtable strt; /* hash table for strings */
+ TValue l_registry;
+ unsigned int seed; /* randomized seed for hashes */
+ lu_byte currentwhite;
+ lu_byte gcstate; /* state of garbage collector */
+ lu_byte gckind; /* kind of GC running */
+ lu_byte gcrunning; /* true if GC is running */
+ int sweepstrgc; /* position of sweep in `strt' */
+ GCObject *allgc; /* list of all collectable objects */
+ GCObject *finobj; /* list of collectable objects with finalizers */
+ GCObject **sweepgc; /* current position of sweep in list 'allgc' */
+ GCObject **sweepfin; /* current position of sweep in list 'finobj' */
+ GCObject *gray; /* list of gray objects */
+ GCObject *grayagain; /* list of objects to be traversed atomically */
+ GCObject *weak; /* list of tables with weak values */
+ GCObject *ephemeron; /* list of ephemeron tables (weak keys) */
+ GCObject *allweak; /* list of all-weak tables */
+ GCObject *tobefnz; /* list of userdata to be GC */
+ UpVal uvhead; /* head of double-linked list of all open upvalues */
+ Mbuffer buff; /* temporary buffer for string concatenation */
+ int gcpause; /* size of pause between successive GCs */
+ int gcmajorinc; /* pause between major collections (only in gen. mode) */
+ int gcstepmul; /* GC `granularity' */
+ lua_CFunction panic; /* to be called in unprotected errors */
+ struct lua_State *mainthread;
+ const lua_Number *version; /* pointer to version number */
+ TString *memerrmsg; /* memory-error message */
+ TString *tmname[TM_N]; /* array with tag-method names */
+ struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
} global_State;
@@ -152,71 +152,71 @@ typedef struct global_State {
** `per thread' state
*/
struct lua_State {
- CommonHeader;
- lu_byte status;
- StkId top; /* first free slot in the stack */
- global_State *l_G;
- CallInfo *ci; /* call info for current function */
- const Instruction *oldpc; /* last pc traced */
- StkId stack_last; /* last free slot in the stack */
- StkId stack; /* stack base */
- int stacksize;
- unsigned short nny; /* number of non-yieldable calls in stack */
- unsigned short nCcalls; /* number of nested C calls */
- lu_byte hookmask;
- lu_byte allowhook;
- int basehookcount;
- int hookcount;
- lua_Hook hook;
- GCObject *openupval; /* list of open upvalues in this stack */
- GCObject *gclist;
- struct lua_longjmp *errorJmp; /* current error recover point */
- ptrdiff_t errfunc; /* current error handling function (stack index) */
- CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
+ CommonHeader;
+ lu_byte status;
+ StkId top; /* first free slot in the stack */
+ global_State *l_G;
+ CallInfo *ci; /* call info for current function */
+ const Instruction *oldpc; /* last pc traced */
+ StkId stack_last; /* last free slot in the stack */
+ StkId stack; /* stack base */
+ int stacksize;
+ unsigned short nny; /* number of non-yieldable calls in stack */
+ unsigned short nCcalls; /* number of nested C calls */
+ lu_byte hookmask;
+ lu_byte allowhook;
+ int basehookcount;
+ int hookcount;
+ lua_Hook hook;
+ GCObject *openupval; /* list of open upvalues in this stack */
+ GCObject *gclist;
+ struct lua_longjmp *errorJmp; /* current error recover point */
+ ptrdiff_t errfunc; /* current error handling function (stack index) */
+ CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
};
-#define G(L) (L->l_G)
+#define G(L) (L->l_G)
/*
** Union of all collectable objects
*/
union GCObject {
- GCheader gch; /* common header */
- union TString ts;
- union Udata u;
- union Closure cl;
- struct Table h;
- struct Proto p;
- struct UpVal uv;
- struct lua_State th; /* thread */
+ GCheader gch; /* common header */
+ union TString ts;
+ union Udata u;
+ union Closure cl;
+ struct Table h;
+ struct Proto p;
+ struct UpVal uv;
+ struct lua_State th; /* thread */
};
-#define gch(o) (&(o)->gch)
+#define gch(o) (&(o)->gch)
/* macros to convert a GCObject into a specific value */
#define rawgco2ts(o) \
check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts))
-#define gco2ts(o) (&rawgco2ts(o)->tsv)
-#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
-#define gco2u(o) (&rawgco2u(o)->uv)
-#define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l))
-#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
+#define gco2ts(o) (&rawgco2ts(o)->tsv)
+#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
+#define gco2u(o) (&rawgco2u(o)->uv)
+#define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l))
+#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
#define gco2cl(o) \
check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl))
-#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
-#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
-#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
-#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
+#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
+#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
+#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
+#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
/* macro to convert any Lua object into a GCObject */
-#define obj2gco(v) (cast(GCObject *, (v)))
+#define obj2gco(v) (cast(GCObject *, (v)))
/* actual number of total bytes allocated */
-#define gettotalbytes(g) ((g)->totalbytes + (g)->GCdebt)
+#define gettotalbytes(g) ((g)->totalbytes + (g)->GCdebt)
LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
@@ -225,4 +225,3 @@ LUAI_FUNC void luaE_freeCI (lua_State *L);
#endif
-
diff --git a/src/lib/lua/lstring.c b/src/lib/lua/lstring.c
index 8b5af0b2e77..47b215e5643 100644
--- a/src/lib/lua/lstring.c
+++ b/src/lib/lua/lstring.c
@@ -23,7 +23,7 @@
** compute its hash
*/
#if !defined(LUAI_HASHLIMIT)
-#define LUAI_HASHLIMIT 5
+#define LUAI_HASHLIMIT 5
#endif
@@ -31,11 +31,11 @@
** equality for long strings
*/
int luaS_eqlngstr (TString *a, TString *b) {
- size_t len = a->tsv.len;
- lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
- return (a == b) || /* same instance or... */
- ((len == b->tsv.len) && /* equal length and ... */
- (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
+ size_t len = a->tsv.len;
+ lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
+ return (a == b) || /* same instance or... */
+ ((len == b->tsv.len) && /* equal length and ... */
+ (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
}
@@ -43,18 +43,18 @@ int luaS_eqlngstr (TString *a, TString *b) {
** equality for strings
*/
int luaS_eqstr (TString *a, TString *b) {
- return (a->tsv.tt == b->tsv.tt) &&
- (a->tsv.tt == LUA_TSHRSTR ? eqshrstr(a, b) : luaS_eqlngstr(a, b));
+ return (a->tsv.tt == b->tsv.tt) &&
+ (a->tsv.tt == LUA_TSHRSTR ? eqshrstr(a, b) : luaS_eqlngstr(a, b));
}
unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
- unsigned int h = seed ^ cast(unsigned int, l);
- size_t l1;
- size_t step = (l >> LUAI_HASHLIMIT) + 1;
- for (l1 = l; l1 >= step; l1 -= step)
- h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
- return h;
+ unsigned int h = seed ^ cast(unsigned int, l);
+ size_t l1;
+ size_t step = (l >> LUAI_HASHLIMIT) + 1;
+ for (l1 = l; l1 >= step; l1 -= step)
+ h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
+ return h;
}
@@ -62,33 +62,33 @@ unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
** resizes the string table
*/
void luaS_resize (lua_State *L, int newsize) {
- int i;
- stringtable *tb = &G(L)->strt;
- /* cannot resize while GC is traversing strings */
- luaC_runtilstate(L, ~bitmask(GCSsweepstring));
- if (newsize > tb->size) {
- luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
- for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;
- }
- /* rehash */
- for (i=0; i<tb->size; i++) {
- GCObject *p = tb->hash[i];
- tb->hash[i] = NULL;
- while (p) { /* for each node in the list */
- GCObject *next = gch(p)->next; /* save next */
- unsigned int h = lmod(gco2ts(p)->hash, newsize); /* new position */
- gch(p)->next = tb->hash[h]; /* chain it */
- tb->hash[h] = p;
- resetoldbit(p); /* see MOVE OLD rule */
- p = next;
- }
- }
- if (newsize < tb->size) {
- /* shrinking slice must be empty */
- lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
- luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
- }
- tb->size = newsize;
+ int i;
+ stringtable *tb = &G(L)->strt;
+ /* cannot resize while GC is traversing strings */
+ luaC_runtilstate(L, ~bitmask(GCSsweepstring));
+ if (newsize > tb->size) {
+ luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
+ for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;
+ }
+ /* rehash */
+ for (i=0; i<tb->size; i++) {
+ GCObject *p = tb->hash[i];
+ tb->hash[i] = NULL;
+ while (p) { /* for each node in the list */
+ GCObject *next = gch(p)->next; /* save next */
+ unsigned int h = lmod(gco2ts(p)->hash, newsize); /* new position */
+ gch(p)->next = tb->hash[h]; /* chain it */
+ tb->hash[h] = p;
+ resetoldbit(p); /* see MOVE OLD rule */
+ p = next;
+ }
+ }
+ if (newsize < tb->size) {
+ /* shrinking slice must be empty */
+ lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
+ luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
+ }
+ tb->size = newsize;
}
@@ -96,17 +96,17 @@ void luaS_resize (lua_State *L, int newsize) {
** creates a new string object
*/
static TString *createstrobj (lua_State *L, const char *str, size_t l,
- int tag, unsigned int h, GCObject **list) {
- TString *ts;
- size_t totalsize; /* total size of TString object */
- totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
- ts = &luaC_newobj(L, tag, totalsize, list, 0)->ts;
- ts->tsv.len = l;
- ts->tsv.hash = h;
- ts->tsv.extra = 0;
- memcpy(ts+1, str, l*sizeof(char));
- ((char *)(ts+1))[l] = '\0'; /* ending 0 */
- return ts;
+ int tag, unsigned int h, GCObject **list) {
+ TString *ts;
+ size_t totalsize; /* total size of TString object */
+ totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
+ ts = &luaC_newobj(L, tag, totalsize, list, 0)->ts;
+ ts->tsv.len = l;
+ ts->tsv.hash = h;
+ ts->tsv.extra = 0;
+ memcpy(ts+1, str, l*sizeof(char));
+ ((char *)(ts+1))[l] = '\0'; /* ending 0 */
+ return ts;
}
@@ -114,16 +114,16 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l,
** creates a new short string, inserting it into string table
*/
static TString *newshrstr (lua_State *L, const char *str, size_t l,
- unsigned int h) {
- GCObject **list; /* (pointer to) list where it will be inserted */
- stringtable *tb = &G(L)->strt;
- TString *s;
- if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
- luaS_resize(L, tb->size*2); /* too crowded */
- list = &tb->hash[lmod(h, tb->size)];
- s = createstrobj(L, str, l, LUA_TSHRSTR, h, list);
- tb->nuse++;
- return s;
+ unsigned int h) {
+ GCObject **list; /* (pointer to) list where it will be inserted */
+ stringtable *tb = &G(L)->strt;
+ TString *s;
+ if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
+ luaS_resize(L, tb->size*2); /* too crowded */
+ list = &tb->hash[lmod(h, tb->size)];
+ s = createstrobj(L, str, l, LUA_TSHRSTR, h, list);
+ tb->nuse++;
+ return s;
}
@@ -131,22 +131,22 @@ static TString *newshrstr (lua_State *L, const char *str, size_t l,
** checks whether short string exists and reuses it or creates a new one
*/
static TString *internshrstr (lua_State *L, const char *str, size_t l) {
- GCObject *o;
- global_State *g = G(L);
- unsigned int h = luaS_hash(str, l, g->seed);
- for (o = g->strt.hash[lmod(h, g->strt.size)];
- o != NULL;
- o = gch(o)->next) {
- TString *ts = rawgco2ts(o);
- if (h == ts->tsv.hash &&
- l == ts->tsv.len &&
- (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
- if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */
- changewhite(o); /* resurrect it */
- return ts;
- }
- }
- return newshrstr(L, str, l, h); /* not found; create a new string */
+ GCObject *o;
+ global_State *g = G(L);
+ unsigned int h = luaS_hash(str, l, g->seed);
+ for (o = g->strt.hash[lmod(h, g->strt.size)];
+ o != NULL;
+ o = gch(o)->next) {
+ TString *ts = rawgco2ts(o);
+ if (h == ts->tsv.hash &&
+ l == ts->tsv.len &&
+ (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
+ if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */
+ changewhite(o); /* resurrect it */
+ return ts;
+ }
+ }
+ return newshrstr(L, str, l, h); /* not found; create a new string */
}
@@ -154,13 +154,13 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
** new string (with explicit length)
*/
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
- if (l <= LUAI_MAXSHORTLEN) /* short string? */
- return internshrstr(L, str, l);
- else {
- if (l + 1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
- luaM_toobig(L);
- return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed, NULL);
- }
+ if (l <= LUAI_MAXSHORTLEN) /* short string? */
+ return internshrstr(L, str, l);
+ else {
+ if (l + 1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
+ luaM_toobig(L);
+ return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed, NULL);
+ }
}
@@ -168,18 +168,17 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
** new zero-terminated string
*/
TString *luaS_new (lua_State *L, const char *str) {
- return luaS_newlstr(L, str, strlen(str));
+ return luaS_newlstr(L, str, strlen(str));
}
Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
- Udata *u;
- if (s > MAX_SIZET - sizeof(Udata))
- luaM_toobig(L);
- u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
- u->uv.len = s;
- u->uv.metatable = NULL;
- u->uv.env = e;
- return u;
+ Udata *u;
+ if (s > MAX_SIZET - sizeof(Udata))
+ luaM_toobig(L);
+ u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
+ u->uv.len = s;
+ u->uv.metatable = NULL;
+ u->uv.env = e;
+ return u;
}
-
diff --git a/src/lib/lua/lstring.h b/src/lib/lua/lstring.h
index d312ff3d2b1..9737e6cf67c 100644
--- a/src/lib/lua/lstring.h
+++ b/src/lib/lua/lstring.h
@@ -12,26 +12,26 @@
#include "lstate.h"
-#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
+#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
-#define sizeudata(u) (sizeof(union Udata)+(u)->len)
+#define sizeudata(u) (sizeof(union Udata)+(u)->len)
-#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
- (sizeof(s)/sizeof(char))-1))
+#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
+ (sizeof(s)/sizeof(char))-1))
-#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
+#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
/*
** test whether a string is a reserved word
*/
-#define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)
+#define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)
/*
** equality for short strings, which are always internalized
*/
-#define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))
+#define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))
LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
diff --git a/src/lib/lua/lstrlib.c b/src/lib/lua/lstrlib.c
index fcc61c9a624..5bccbf604ee 100644
--- a/src/lib/lua/lstrlib.c
+++ b/src/lib/lua/lstrlib.c
@@ -25,161 +25,161 @@
** pattern-matching. This limit is arbitrary.
*/
#if !defined(LUA_MAXCAPTURES)
-#define LUA_MAXCAPTURES 32
+#define LUA_MAXCAPTURES 32
#endif
/* macro to `unsign' a character */
-#define uchar(c) ((unsigned char)(c))
+#define uchar(c) ((unsigned char)(c))
static int str_len (lua_State *L) {
- size_t l;
- luaL_checklstring(L, 1, &l);
- lua_pushinteger(L, (lua_Integer)l);
- return 1;
+ size_t l;
+ luaL_checklstring(L, 1, &l);
+ lua_pushinteger(L, (lua_Integer)l);
+ return 1;
}
/* translate a relative string position: negative means back from end */
static size_t posrelat (ptrdiff_t pos, size_t len) {
- if (pos >= 0) return (size_t)pos;
- else if (0u - (size_t)pos > len) return 0;
- else return len - ((size_t)-pos) + 1;
+ if (pos >= 0) return (size_t)pos;
+ else if (0u - (size_t)pos > len) return 0;
+ else return len - ((size_t)-pos) + 1;
}
static int str_sub (lua_State *L) {
- size_t l;
- const char *s = luaL_checklstring(L, 1, &l);
- size_t start = posrelat(luaL_checkinteger(L, 2), l);
- size_t end = posrelat(luaL_optinteger(L, 3, -1), l);
- if (start < 1) start = 1;
- if (end > l) end = l;
- if (start <= end)
- lua_pushlstring(L, s + start - 1, end - start + 1);
- else lua_pushliteral(L, "");
- return 1;
+ size_t l;
+ const char *s = luaL_checklstring(L, 1, &l);
+ size_t start = posrelat(luaL_checkinteger(L, 2), l);
+ size_t end = posrelat(luaL_optinteger(L, 3, -1), l);
+ if (start < 1) start = 1;
+ if (end > l) end = l;
+ if (start <= end)
+ lua_pushlstring(L, s + start - 1, end - start + 1);
+ else lua_pushliteral(L, "");
+ return 1;
}
static int str_reverse (lua_State *L) {
- size_t l, i;
- luaL_Buffer b;
- const char *s = luaL_checklstring(L, 1, &l);
- char *p = luaL_buffinitsize(L, &b, l);
- for (i = 0; i < l; i++)
- p[i] = s[l - i - 1];
- luaL_pushresultsize(&b, l);
- return 1;
+ size_t l, i;
+ luaL_Buffer b;
+ const char *s = luaL_checklstring(L, 1, &l);
+ char *p = luaL_buffinitsize(L, &b, l);
+ for (i = 0; i < l; i++)
+ p[i] = s[l - i - 1];
+ luaL_pushresultsize(&b, l);
+ return 1;
}
static int str_lower (lua_State *L) {
- size_t l;
- size_t i;
- luaL_Buffer b;
- const char *s = luaL_checklstring(L, 1, &l);
- char *p = luaL_buffinitsize(L, &b, l);
- for (i=0; i<l; i++)
- p[i] = tolower(uchar(s[i]));
- luaL_pushresultsize(&b, l);
- return 1;
+ size_t l;
+ size_t i;
+ luaL_Buffer b;
+ const char *s = luaL_checklstring(L, 1, &l);
+ char *p = luaL_buffinitsize(L, &b, l);
+ for (i=0; i<l; i++)
+ p[i] = tolower(uchar(s[i]));
+ luaL_pushresultsize(&b, l);
+ return 1;
}
static int str_upper (lua_State *L) {
- size_t l;
- size_t i;
- luaL_Buffer b;
- const char *s = luaL_checklstring(L, 1, &l);
- char *p = luaL_buffinitsize(L, &b, l);
- for (i=0; i<l; i++)
- p[i] = toupper(uchar(s[i]));
- luaL_pushresultsize(&b, l);
- return 1;
+ size_t l;
+ size_t i;
+ luaL_Buffer b;
+ const char *s = luaL_checklstring(L, 1, &l);
+ char *p = luaL_buffinitsize(L, &b, l);
+ for (i=0; i<l; i++)
+ p[i] = toupper(uchar(s[i]));
+ luaL_pushresultsize(&b, l);
+ return 1;
}
/* reasonable limit to avoid arithmetic overflow */
-#define MAXSIZE ((~(size_t)0) >> 1)
+#define MAXSIZE ((~(size_t)0) >> 1)
static int str_rep (lua_State *L) {
- size_t l, lsep;
- const char *s = luaL_checklstring(L, 1, &l);
- int n = luaL_checkint(L, 2);
- const char *sep = luaL_optlstring(L, 3, "", &lsep);
- if (n <= 0) lua_pushliteral(L, "");
- else if (l + lsep < l || l + lsep >= MAXSIZE / n) /* may overflow? */
- return luaL_error(L, "resulting string too large");
- else {
- size_t totallen = n * l + (n - 1) * lsep;
- luaL_Buffer b;
- char *p = luaL_buffinitsize(L, &b, totallen);
- while (n-- > 1) { /* first n-1 copies (followed by separator) */
- memcpy(p, s, l * sizeof(char)); p += l;
- if (lsep > 0) { /* avoid empty 'memcpy' (may be expensive) */
- memcpy(p, sep, lsep * sizeof(char)); p += lsep;
- }
- }
- memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
- luaL_pushresultsize(&b, totallen);
- }
- return 1;
+ size_t l, lsep;
+ const char *s = luaL_checklstring(L, 1, &l);
+ int n = luaL_checkint(L, 2);
+ const char *sep = luaL_optlstring(L, 3, "", &lsep);
+ if (n <= 0) lua_pushliteral(L, "");
+ else if (l + lsep < l || l + lsep >= MAXSIZE / n) /* may overflow? */
+ return luaL_error(L, "resulting string too large");
+ else {
+ size_t totallen = n * l + (n - 1) * lsep;
+ luaL_Buffer b;
+ char *p = luaL_buffinitsize(L, &b, totallen);
+ while (n-- > 1) { /* first n-1 copies (followed by separator) */
+ memcpy(p, s, l * sizeof(char)); p += l;
+ if (lsep > 0) { /* avoid empty 'memcpy' (may be expensive) */
+ memcpy(p, sep, lsep * sizeof(char)); p += lsep;
+ }
+ }
+ memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
+ luaL_pushresultsize(&b, totallen);
+ }
+ return 1;
}
static int str_byte (lua_State *L) {
- size_t l;
- const char *s = luaL_checklstring(L, 1, &l);
- size_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
- size_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
- int n, i;
- if (posi < 1) posi = 1;
- if (pose > l) pose = l;
- if (posi > pose) return 0; /* empty interval; return no values */
- n = (int)(pose - posi + 1);
- if (posi + n <= pose) /* (size_t -> int) overflow? */
- return luaL_error(L, "string slice too long");
- luaL_checkstack(L, n, "string slice too long");
- for (i=0; i<n; i++)
- lua_pushinteger(L, uchar(s[posi+i-1]));
- return n;
+ size_t l;
+ const char *s = luaL_checklstring(L, 1, &l);
+ size_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
+ size_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
+ int n, i;
+ if (posi < 1) posi = 1;
+ if (pose > l) pose = l;
+ if (posi > pose) return 0; /* empty interval; return no values */
+ n = (int)(pose - posi + 1);
+ if (posi + n <= pose) /* (size_t -> int) overflow? */
+ return luaL_error(L, "string slice too long");
+ luaL_checkstack(L, n, "string slice too long");
+ for (i=0; i<n; i++)
+ lua_pushinteger(L, uchar(s[posi+i-1]));
+ return n;
}
static int str_char (lua_State *L) {
- int n = lua_gettop(L); /* number of arguments */
- int i;
- luaL_Buffer b;
- char *p = luaL_buffinitsize(L, &b, n);
- for (i=1; i<=n; i++) {
- int c = luaL_checkint(L, i);
- luaL_argcheck(L, uchar(c) == c, i, "value out of range");
- p[i - 1] = uchar(c);
- }
- luaL_pushresultsize(&b, n);
- return 1;
+ int n = lua_gettop(L); /* number of arguments */
+ int i;
+ luaL_Buffer b;
+ char *p = luaL_buffinitsize(L, &b, n);
+ for (i=1; i<=n; i++) {
+ int c = luaL_checkint(L, i);
+ luaL_argcheck(L, uchar(c) == c, i, "value out of range");
+ p[i - 1] = uchar(c);
+ }
+ luaL_pushresultsize(&b, n);
+ return 1;
}
static int writer (lua_State *L, const void* b, size_t size, void* B) {
- (void)L;
- luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
- return 0;
+ (void)L;
+ luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
+ return 0;
}
static int str_dump (lua_State *L) {
- luaL_Buffer b;
- luaL_checktype(L, 1, LUA_TFUNCTION);
- lua_settop(L, 1);
- luaL_buffinit(L,&b);
- if (lua_dump(L, writer, &b) != 0)
- return luaL_error(L, "unable to dump given function");
- luaL_pushresult(&b);
- return 1;
+ luaL_Buffer b;
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+ lua_settop(L, 1);
+ luaL_buffinit(L,&b);
+ if (lua_dump(L, writer, &b) != 0)
+ return luaL_error(L, "unable to dump given function");
+ luaL_pushresult(&b);
+ return 1;
}
@@ -191,21 +191,21 @@ static int str_dump (lua_State *L) {
*/
-#define CAP_UNFINISHED (-1)
-#define CAP_POSITION (-2)
+#define CAP_UNFINISHED (-1)
+#define CAP_POSITION (-2)
typedef struct MatchState {
- int matchdepth; /* control for recursive depth (to avoid C stack overflow) */
- const char *src_init; /* init of source string */
- const char *src_end; /* end ('\0') of source string */
- const char *p_end; /* end ('\0') of pattern */
- lua_State *L;
- int level; /* total number of captures (finished or unfinished) */
- struct {
- const char *init;
- ptrdiff_t len;
- } capture[LUA_MAXCAPTURES];
+ int matchdepth; /* control for recursive depth (to avoid C stack overflow) */
+ const char *src_init; /* init of source string */
+ const char *src_end; /* end ('\0') of source string */
+ const char *p_end; /* end ('\0') of pattern */
+ lua_State *L;
+ int level; /* total number of captures (finished or unfinished) */
+ struct {
+ const char *init;
+ ptrdiff_t len;
+ } capture[LUA_MAXCAPTURES];
} MatchState;
@@ -215,565 +215,565 @@ static const char *match (MatchState *ms, const char *s, const char *p);
/* maximum recursion depth for 'match' */
#if !defined(MAXCCALLS)
-#define MAXCCALLS 200
+#define MAXCCALLS 200
#endif
-#define L_ESC '%'
-#define SPECIALS "^$*+?.([%-"
+#define L_ESC '%'
+#define SPECIALS "^$*+?.([%-"
static int check_capture (MatchState *ms, int l) {
- l -= '1';
- if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
- return luaL_error(ms->L, "invalid capture index %%%d", l + 1);
- return l;
+ l -= '1';
+ if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
+ return luaL_error(ms->L, "invalid capture index %%%d", l + 1);
+ return l;
}
static int capture_to_close (MatchState *ms) {
- int level = ms->level;
- for (level--; level>=0; level--)
- if (ms->capture[level].len == CAP_UNFINISHED) return level;
- return luaL_error(ms->L, "invalid pattern capture");
+ int level = ms->level;
+ for (level--; level>=0; level--)
+ if (ms->capture[level].len == CAP_UNFINISHED) return level;
+ return luaL_error(ms->L, "invalid pattern capture");
}
static const char *classend (MatchState *ms, const char *p) {
- switch (*p++) {
- case L_ESC: {
- if (p == ms->p_end)
- luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")");
- return p+1;
- }
- case '[': {
- if (*p == '^') p++;
- do { /* look for a `]' */
- if (p == ms->p_end)
- luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")");
- if (*(p++) == L_ESC && p < ms->p_end)
- p++; /* skip escapes (e.g. `%]') */
- } while (*p != ']');
- return p+1;
- }
- default: {
- return p;
- }
- }
+ switch (*p++) {
+ case L_ESC: {
+ if (p == ms->p_end)
+ luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")");
+ return p+1;
+ }
+ case '[': {
+ if (*p == '^') p++;
+ do { /* look for a `]' */
+ if (p == ms->p_end)
+ luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")");
+ if (*(p++) == L_ESC && p < ms->p_end)
+ p++; /* skip escapes (e.g. `%]') */
+ } while (*p != ']');
+ return p+1;
+ }
+ default: {
+ return p;
+ }
+ }
}
static int match_class (int c, int cl) {
- int res;
- switch (tolower(cl)) {
- case 'a' : res = isalpha(c); break;
- case 'c' : res = iscntrl(c); break;
- case 'd' : res = isdigit(c); break;
- case 'g' : res = isgraph(c); break;
- case 'l' : res = islower(c); break;
- case 'p' : res = ispunct(c); break;
- case 's' : res = isspace(c); break;
- case 'u' : res = isupper(c); break;
- case 'w' : res = isalnum(c); break;
- case 'x' : res = isxdigit(c); break;
- case 'z' : res = (c == 0); break; /* deprecated option */
- default: return (cl == c);
- }
- return (islower(cl) ? res : !res);
+ int res;
+ switch (tolower(cl)) {
+ case 'a' : res = isalpha(c); break;
+ case 'c' : res = iscntrl(c); break;
+ case 'd' : res = isdigit(c); break;
+ case 'g' : res = isgraph(c); break;
+ case 'l' : res = islower(c); break;
+ case 'p' : res = ispunct(c); break;
+ case 's' : res = isspace(c); break;
+ case 'u' : res = isupper(c); break;
+ case 'w' : res = isalnum(c); break;
+ case 'x' : res = isxdigit(c); break;
+ case 'z' : res = (c == 0); break; /* deprecated option */
+ default: return (cl == c);
+ }
+ return (islower(cl) ? res : !res);
}
static int matchbracketclass (int c, const char *p, const char *ec) {
- int sig = 1;
- if (*(p+1) == '^') {
- sig = 0;
- p++; /* skip the `^' */
- }
- while (++p < ec) {
- if (*p == L_ESC) {
- p++;
- if (match_class(c, uchar(*p)))
- return sig;
- }
- else if ((*(p+1) == '-') && (p+2 < ec)) {
- p+=2;
- if (uchar(*(p-2)) <= c && c <= uchar(*p))
- return sig;
- }
- else if (uchar(*p) == c) return sig;
- }
- return !sig;
+ int sig = 1;
+ if (*(p+1) == '^') {
+ sig = 0;
+ p++; /* skip the `^' */
+ }
+ while (++p < ec) {
+ if (*p == L_ESC) {
+ p++;
+ if (match_class(c, uchar(*p)))
+ return sig;
+ }
+ else if ((*(p+1) == '-') && (p+2 < ec)) {
+ p+=2;
+ if (uchar(*(p-2)) <= c && c <= uchar(*p))
+ return sig;
+ }
+ else if (uchar(*p) == c) return sig;
+ }
+ return !sig;
}
static int singlematch (MatchState *ms, const char *s, const char *p,
- const char *ep) {
- if (s >= ms->src_end)
- return 0;
- else {
- int c = uchar(*s);
- switch (*p) {
- case '.': return 1; /* matches any char */
- case L_ESC: return match_class(c, uchar(*(p+1)));
- case '[': return matchbracketclass(c, p, ep-1);
- default: return (uchar(*p) == c);
- }
- }
+ const char *ep) {
+ if (s >= ms->src_end)
+ return 0;
+ else {
+ int c = uchar(*s);
+ switch (*p) {
+ case '.': return 1; /* matches any char */
+ case L_ESC: return match_class(c, uchar(*(p+1)));
+ case '[': return matchbracketclass(c, p, ep-1);
+ default: return (uchar(*p) == c);
+ }
+ }
}
static const char *matchbalance (MatchState *ms, const char *s,
- const char *p) {
- if (p >= ms->p_end - 1)
- luaL_error(ms->L, "malformed pattern "
- "(missing arguments to " LUA_QL("%%b") ")");
- if (*s != *p) return NULL;
- else {
- int b = *p;
- int e = *(p+1);
- int cont = 1;
- while (++s < ms->src_end) {
- if (*s == e) {
- if (--cont == 0) return s+1;
- }
- else if (*s == b) cont++;
- }
- }
- return NULL; /* string ends out of balance */
+ const char *p) {
+ if (p >= ms->p_end - 1)
+ luaL_error(ms->L, "malformed pattern "
+ "(missing arguments to " LUA_QL("%%b") ")");
+ if (*s != *p) return NULL;
+ else {
+ int b = *p;
+ int e = *(p+1);
+ int cont = 1;
+ while (++s < ms->src_end) {
+ if (*s == e) {
+ if (--cont == 0) return s+1;
+ }
+ else if (*s == b) cont++;
+ }
+ }
+ return NULL; /* string ends out of balance */
}
static const char *max_expand (MatchState *ms, const char *s,
- const char *p, const char *ep) {
- ptrdiff_t i = 0; /* counts maximum expand for item */
- while (singlematch(ms, s + i, p, ep))
- i++;
- /* keeps trying to match with the maximum repetitions */
- while (i>=0) {
- const char *res = match(ms, (s+i), ep+1);
- if (res) return res;
- i--; /* else didn't match; reduce 1 repetition to try again */
- }
- return NULL;
+ const char *p, const char *ep) {
+ ptrdiff_t i = 0; /* counts maximum expand for item */
+ while (singlematch(ms, s + i, p, ep))
+ i++;
+ /* keeps trying to match with the maximum repetitions */
+ while (i>=0) {
+ const char *res = match(ms, (s+i), ep+1);
+ if (res) return res;
+ i--; /* else didn't match; reduce 1 repetition to try again */
+ }
+ return NULL;
}
static const char *min_expand (MatchState *ms, const char *s,
- const char *p, const char *ep) {
- for (;;) {
- const char *res = match(ms, s, ep+1);
- if (res != NULL)
- return res;
- else if (singlematch(ms, s, p, ep))
- s++; /* try with one more repetition */
- else return NULL;
- }
+ const char *p, const char *ep) {
+ for (;;) {
+ const char *res = match(ms, s, ep+1);
+ if (res != NULL)
+ return res;
+ else if (singlematch(ms, s, p, ep))
+ s++; /* try with one more repetition */
+ else return NULL;
+ }
}
static const char *start_capture (MatchState *ms, const char *s,
- const char *p, int what) {
- const char *res;
- int level = ms->level;
- if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures");
- ms->capture[level].init = s;
- ms->capture[level].len = what;
- ms->level = level+1;
- if ((res=match(ms, s, p)) == NULL) /* match failed? */
- ms->level--; /* undo capture */
- return res;
+ const char *p, int what) {
+ const char *res;
+ int level = ms->level;
+ if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures");
+ ms->capture[level].init = s;
+ ms->capture[level].len = what;
+ ms->level = level+1;
+ if ((res=match(ms, s, p)) == NULL) /* match failed? */
+ ms->level--; /* undo capture */
+ return res;
}
static const char *end_capture (MatchState *ms, const char *s,
- const char *p) {
- int l = capture_to_close(ms);
- const char *res;
- ms->capture[l].len = s - ms->capture[l].init; /* close capture */
- if ((res = match(ms, s, p)) == NULL) /* match failed? */
- ms->capture[l].len = CAP_UNFINISHED; /* undo capture */
- return res;
+ const char *p) {
+ int l = capture_to_close(ms);
+ const char *res;
+ ms->capture[l].len = s - ms->capture[l].init; /* close capture */
+ if ((res = match(ms, s, p)) == NULL) /* match failed? */
+ ms->capture[l].len = CAP_UNFINISHED; /* undo capture */
+ return res;
}
static const char *match_capture (MatchState *ms, const char *s, int l) {
- size_t len;
- l = check_capture(ms, l);
- len = ms->capture[l].len;
- if ((size_t)(ms->src_end-s) >= len &&
- memcmp(ms->capture[l].init, s, len) == 0)
- return s+len;
- else return NULL;
+ size_t len;
+ l = check_capture(ms, l);
+ len = ms->capture[l].len;
+ if ((size_t)(ms->src_end-s) >= len &&
+ memcmp(ms->capture[l].init, s, len) == 0)
+ return s+len;
+ else return NULL;
}
static const char *match (MatchState *ms, const char *s, const char *p) {
- if (ms->matchdepth-- == 0)
- luaL_error(ms->L, "pattern too complex");
- init: /* using goto's to optimize tail recursion */
- if (p != ms->p_end) { /* end of pattern? */
- switch (*p) {
- case '(': { /* start capture */
- if (*(p + 1) == ')') /* position capture? */
- s = start_capture(ms, s, p + 2, CAP_POSITION);
- else
- s = start_capture(ms, s, p + 1, CAP_UNFINISHED);
- break;
- }
- case ')': { /* end capture */
- s = end_capture(ms, s, p + 1);
- break;
- }
- case '$': {
- if ((p + 1) != ms->p_end) /* is the `$' the last char in pattern? */
- goto dflt; /* no; go to default */
- s = (s == ms->src_end) ? s : NULL; /* check end of string */
- break;
- }
- case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
- switch (*(p + 1)) {
- case 'b': { /* balanced string? */
- s = matchbalance(ms, s, p + 2);
- if (s != NULL) {
- p += 4; goto init; /* return match(ms, s, p + 4); */
- } /* else fail (s == NULL) */
- break;
- }
- case 'f': { /* frontier? */
- const char *ep; char previous;
- p += 2;
- if (*p != '[')
- luaL_error(ms->L, "missing " LUA_QL("[") " after "
- LUA_QL("%%f") " in pattern");
- ep = classend(ms, p); /* points to what is next */
- previous = (s == ms->src_init) ? '\0' : *(s - 1);
- if (!matchbracketclass(uchar(previous), p, ep - 1) &&
- matchbracketclass(uchar(*s), p, ep - 1)) {
- p = ep; goto init; /* return match(ms, s, ep); */
- }
- s = NULL; /* match failed */
- break;
- }
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- case '8': case '9': { /* capture results (%0-%9)? */
- s = match_capture(ms, s, uchar(*(p + 1)));
- if (s != NULL) {
- p += 2; goto init; /* return match(ms, s, p + 2) */
- }
- break;
- }
- default: goto dflt;
- }
- break;
- }
- default: dflt: { /* pattern class plus optional suffix */
- const char *ep = classend(ms, p); /* points to optional suffix */
- /* does not match at least once? */
- if (!singlematch(ms, s, p, ep)) {
- if (*ep == '*' || *ep == '?' || *ep == '-') { /* accept empty? */
- p = ep + 1; goto init; /* return match(ms, s, ep + 1); */
- }
- else /* '+' or no suffix */
- s = NULL; /* fail */
- }
- else { /* matched once */
- switch (*ep) { /* handle optional suffix */
- case '?': { /* optional */
- const char *res;
- if ((res = match(ms, s + 1, ep + 1)) != NULL)
- s = res;
- else {
- p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */
- }
- break;
- }
- case '+': /* 1 or more repetitions */
- s++; /* 1 match already done */
- /* go through */
- case '*': /* 0 or more repetitions */
- s = max_expand(ms, s, p, ep);
- break;
- case '-': /* 0 or more repetitions (minimum) */
- s = min_expand(ms, s, p, ep);
- break;
- default: /* no suffix */
- s++; p = ep; goto init; /* return match(ms, s + 1, ep); */
- }
- }
- break;
- }
- }
- }
- ms->matchdepth++;
- return s;
+ if (ms->matchdepth-- == 0)
+ luaL_error(ms->L, "pattern too complex");
+ init: /* using goto's to optimize tail recursion */
+ if (p != ms->p_end) { /* end of pattern? */
+ switch (*p) {
+ case '(': { /* start capture */
+ if (*(p + 1) == ')') /* position capture? */
+ s = start_capture(ms, s, p + 2, CAP_POSITION);
+ else
+ s = start_capture(ms, s, p + 1, CAP_UNFINISHED);
+ break;
+ }
+ case ')': { /* end capture */
+ s = end_capture(ms, s, p + 1);
+ break;
+ }
+ case '$': {
+ if ((p + 1) != ms->p_end) /* is the `$' the last char in pattern? */
+ goto dflt; /* no; go to default */
+ s = (s == ms->src_end) ? s : NULL; /* check end of string */
+ break;
+ }
+ case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
+ switch (*(p + 1)) {
+ case 'b': { /* balanced string? */
+ s = matchbalance(ms, s, p + 2);
+ if (s != NULL) {
+ p += 4; goto init; /* return match(ms, s, p + 4); */
+ } /* else fail (s == NULL) */
+ break;
+ }
+ case 'f': { /* frontier? */
+ const char *ep; char previous;
+ p += 2;
+ if (*p != '[')
+ luaL_error(ms->L, "missing " LUA_QL("[") " after "
+ LUA_QL("%%f") " in pattern");
+ ep = classend(ms, p); /* points to what is next */
+ previous = (s == ms->src_init) ? '\0' : *(s - 1);
+ if (!matchbracketclass(uchar(previous), p, ep - 1) &&
+ matchbracketclass(uchar(*s), p, ep - 1)) {
+ p = ep; goto init; /* return match(ms, s, ep); */
+ }
+ s = NULL; /* match failed */
+ break;
+ }
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ case '8': case '9': { /* capture results (%0-%9)? */
+ s = match_capture(ms, s, uchar(*(p + 1)));
+ if (s != NULL) {
+ p += 2; goto init; /* return match(ms, s, p + 2) */
+ }
+ break;
+ }
+ default: goto dflt;
+ }
+ break;
+ }
+ default: dflt: { /* pattern class plus optional suffix */
+ const char *ep = classend(ms, p); /* points to optional suffix */
+ /* does not match at least once? */
+ if (!singlematch(ms, s, p, ep)) {
+ if (*ep == '*' || *ep == '?' || *ep == '-') { /* accept empty? */
+ p = ep + 1; goto init; /* return match(ms, s, ep + 1); */
+ }
+ else /* '+' or no suffix */
+ s = NULL; /* fail */
+ }
+ else { /* matched once */
+ switch (*ep) { /* handle optional suffix */
+ case '?': { /* optional */
+ const char *res;
+ if ((res = match(ms, s + 1, ep + 1)) != NULL)
+ s = res;
+ else {
+ p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */
+ }
+ break;
+ }
+ case '+': /* 1 or more repetitions */
+ s++; /* 1 match already done */
+ /* go through */
+ case '*': /* 0 or more repetitions */
+ s = max_expand(ms, s, p, ep);
+ break;
+ case '-': /* 0 or more repetitions (minimum) */
+ s = min_expand(ms, s, p, ep);
+ break;
+ default: /* no suffix */
+ s++; p = ep; goto init; /* return match(ms, s + 1, ep); */
+ }
+ }
+ break;
+ }
+ }
+ }
+ ms->matchdepth++;
+ return s;
}
static const char *lmemfind (const char *s1, size_t l1,
- const char *s2, size_t l2) {
- if (l2 == 0) return s1; /* empty strings are everywhere */
- else if (l2 > l1) return NULL; /* avoids a negative `l1' */
- else {
- const char *init; /* to search for a `*s2' inside `s1' */
- l2--; /* 1st char will be checked by `memchr' */
- l1 = l1-l2; /* `s2' cannot be found after that */
- while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
- init++; /* 1st char is already checked */
- if (memcmp(init, s2+1, l2) == 0)
- return init-1;
- else { /* correct `l1' and `s1' to try again */
- l1 -= init-s1;
- s1 = init;
- }
- }
- return NULL; /* not found */
- }
+ const char *s2, size_t l2) {
+ if (l2 == 0) return s1; /* empty strings are everywhere */
+ else if (l2 > l1) return NULL; /* avoids a negative `l1' */
+ else {
+ const char *init; /* to search for a `*s2' inside `s1' */
+ l2--; /* 1st char will be checked by `memchr' */
+ l1 = l1-l2; /* `s2' cannot be found after that */
+ while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
+ init++; /* 1st char is already checked */
+ if (memcmp(init, s2+1, l2) == 0)
+ return init-1;
+ else { /* correct `l1' and `s1' to try again */
+ l1 -= init-s1;
+ s1 = init;
+ }
+ }
+ return NULL; /* not found */
+ }
}
static void push_onecapture (MatchState *ms, int i, const char *s,
- const char *e) {
- if (i >= ms->level) {
- if (i == 0) /* ms->level == 0, too */
- lua_pushlstring(ms->L, s, e - s); /* add whole match */
- else
- luaL_error(ms->L, "invalid capture index");
- }
- else {
- ptrdiff_t l = ms->capture[i].len;
- if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
- if (l == CAP_POSITION)
- lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
- else
- lua_pushlstring(ms->L, ms->capture[i].init, l);
- }
+ const char *e) {
+ if (i >= ms->level) {
+ if (i == 0) /* ms->level == 0, too */
+ lua_pushlstring(ms->L, s, e - s); /* add whole match */
+ else
+ luaL_error(ms->L, "invalid capture index");
+ }
+ else {
+ ptrdiff_t l = ms->capture[i].len;
+ if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
+ if (l == CAP_POSITION)
+ lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
+ else
+ lua_pushlstring(ms->L, ms->capture[i].init, l);
+ }
}
static int push_captures (MatchState *ms, const char *s, const char *e) {
- int i;
- int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
- luaL_checkstack(ms->L, nlevels, "too many captures");
- for (i = 0; i < nlevels; i++)
- push_onecapture(ms, i, s, e);
- return nlevels; /* number of strings pushed */
+ int i;
+ int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
+ luaL_checkstack(ms->L, nlevels, "too many captures");
+ for (i = 0; i < nlevels; i++)
+ push_onecapture(ms, i, s, e);
+ return nlevels; /* number of strings pushed */
}
/* check whether pattern has no special characters */
static int nospecials (const char *p, size_t l) {
- size_t upto = 0;
- do {
- if (strpbrk(p + upto, SPECIALS))
- return 0; /* pattern has a special character */
- upto += strlen(p + upto) + 1; /* may have more after \0 */
- } while (upto <= l);
- return 1; /* no special chars found */
+ size_t upto = 0;
+ do {
+ if (strpbrk(p + upto, SPECIALS))
+ return 0; /* pattern has a special character */
+ upto += strlen(p + upto) + 1; /* may have more after \0 */
+ } while (upto <= l);
+ return 1; /* no special chars found */
}
static int str_find_aux (lua_State *L, int find) {
- size_t ls, lp;
- const char *s = luaL_checklstring(L, 1, &ls);
- const char *p = luaL_checklstring(L, 2, &lp);
- size_t init = posrelat(luaL_optinteger(L, 3, 1), ls);
- if (init < 1) init = 1;
- else if (init > ls + 1) { /* start after string's end? */
- lua_pushnil(L); /* cannot find anything */
- return 1;
- }
- /* explicit request or no special characters? */
- if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
- /* do a plain search */
- const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp);
- if (s2) {
- lua_pushinteger(L, s2 - s + 1);
- lua_pushinteger(L, s2 - s + lp);
- return 2;
- }
- }
- else {
- MatchState ms;
- const char *s1 = s + init - 1;
- int anchor = (*p == '^');
- if (anchor) {
- p++; lp--; /* skip anchor character */
- }
- ms.L = L;
- ms.matchdepth = MAXCCALLS;
- ms.src_init = s;
- ms.src_end = s + ls;
- ms.p_end = p + lp;
- do {
- const char *res;
- ms.level = 0;
- lua_assert(ms.matchdepth == MAXCCALLS);
- if ((res=match(&ms, s1, p)) != NULL) {
- if (find) {
- lua_pushinteger(L, s1 - s + 1); /* start */
- lua_pushinteger(L, res - s); /* end */
- return push_captures(&ms, NULL, 0) + 2;
- }
- else
- return push_captures(&ms, s1, res);
- }
- } while (s1++ < ms.src_end && !anchor);
- }
- lua_pushnil(L); /* not found */
- return 1;
+ size_t ls, lp;
+ const char *s = luaL_checklstring(L, 1, &ls);
+ const char *p = luaL_checklstring(L, 2, &lp);
+ size_t init = posrelat(luaL_optinteger(L, 3, 1), ls);
+ if (init < 1) init = 1;
+ else if (init > ls + 1) { /* start after string's end? */
+ lua_pushnil(L); /* cannot find anything */
+ return 1;
+ }
+ /* explicit request or no special characters? */
+ if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
+ /* do a plain search */
+ const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp);
+ if (s2) {
+ lua_pushinteger(L, s2 - s + 1);
+ lua_pushinteger(L, s2 - s + lp);
+ return 2;
+ }
+ }
+ else {
+ MatchState ms;
+ const char *s1 = s + init - 1;
+ int anchor = (*p == '^');
+ if (anchor) {
+ p++; lp--; /* skip anchor character */
+ }
+ ms.L = L;
+ ms.matchdepth = MAXCCALLS;
+ ms.src_init = s;
+ ms.src_end = s + ls;
+ ms.p_end = p + lp;
+ do {
+ const char *res;
+ ms.level = 0;
+ lua_assert(ms.matchdepth == MAXCCALLS);
+ if ((res=match(&ms, s1, p)) != NULL) {
+ if (find) {
+ lua_pushinteger(L, s1 - s + 1); /* start */
+ lua_pushinteger(L, res - s); /* end */
+ return push_captures(&ms, NULL, 0) + 2;
+ }
+ else
+ return push_captures(&ms, s1, res);
+ }
+ } while (s1++ < ms.src_end && !anchor);
+ }
+ lua_pushnil(L); /* not found */
+ return 1;
}
static int str_find (lua_State *L) {
- return str_find_aux(L, 1);
+ return str_find_aux(L, 1);
}
static int str_match (lua_State *L) {
- return str_find_aux(L, 0);
+ return str_find_aux(L, 0);
}
static int gmatch_aux (lua_State *L) {
- MatchState ms;
- size_t ls, lp;
- const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
- const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
- const char *src;
- ms.L = L;
- ms.matchdepth = MAXCCALLS;
- ms.src_init = s;
- ms.src_end = s+ls;
- ms.p_end = p + lp;
- for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
- src <= ms.src_end;
- src++) {
- const char *e;
- ms.level = 0;
- lua_assert(ms.matchdepth == MAXCCALLS);
- if ((e = match(&ms, src, p)) != NULL) {
- lua_Integer newstart = e-s;
- if (e == src) newstart++; /* empty match? go at least one position */
- lua_pushinteger(L, newstart);
- lua_replace(L, lua_upvalueindex(3));
- return push_captures(&ms, src, e);
- }
- }
- return 0; /* not found */
+ MatchState ms;
+ size_t ls, lp;
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
+ const char *src;
+ ms.L = L;
+ ms.matchdepth = MAXCCALLS;
+ ms.src_init = s;
+ ms.src_end = s+ls;
+ ms.p_end = p + lp;
+ for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
+ src <= ms.src_end;
+ src++) {
+ const char *e;
+ ms.level = 0;
+ lua_assert(ms.matchdepth == MAXCCALLS);
+ if ((e = match(&ms, src, p)) != NULL) {
+ lua_Integer newstart = e-s;
+ if (e == src) newstart++; /* empty match? go at least one position */
+ lua_pushinteger(L, newstart);
+ lua_replace(L, lua_upvalueindex(3));
+ return push_captures(&ms, src, e);
+ }
+ }
+ return 0; /* not found */
}
static int gmatch (lua_State *L) {
- luaL_checkstring(L, 1);
- luaL_checkstring(L, 2);
- lua_settop(L, 2);
- lua_pushinteger(L, 0);
- lua_pushcclosure(L, gmatch_aux, 3);
- return 1;
+ luaL_checkstring(L, 1);
+ luaL_checkstring(L, 2);
+ lua_settop(L, 2);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, gmatch_aux, 3);
+ return 1;
}
static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
- const char *e) {
- size_t l, i;
- const char *news = lua_tolstring(ms->L, 3, &l);
- for (i = 0; i < l; i++) {
- if (news[i] != L_ESC)
- luaL_addchar(b, news[i]);
- else {
- i++; /* skip ESC */
- if (!isdigit(uchar(news[i]))) {
- if (news[i] != L_ESC)
- luaL_error(ms->L, "invalid use of " LUA_QL("%c")
- " in replacement string", L_ESC);
- luaL_addchar(b, news[i]);
- }
- else if (news[i] == '0')
- luaL_addlstring(b, s, e - s);
- else {
- push_onecapture(ms, news[i] - '1', s, e);
- luaL_addvalue(b); /* add capture to accumulated result */
- }
- }
- }
+ const char *e) {
+ size_t l, i;
+ const char *news = lua_tolstring(ms->L, 3, &l);
+ for (i = 0; i < l; i++) {
+ if (news[i] != L_ESC)
+ luaL_addchar(b, news[i]);
+ else {
+ i++; /* skip ESC */
+ if (!isdigit(uchar(news[i]))) {
+ if (news[i] != L_ESC)
+ luaL_error(ms->L, "invalid use of " LUA_QL("%c")
+ " in replacement string", L_ESC);
+ luaL_addchar(b, news[i]);
+ }
+ else if (news[i] == '0')
+ luaL_addlstring(b, s, e - s);
+ else {
+ push_onecapture(ms, news[i] - '1', s, e);
+ luaL_addvalue(b); /* add capture to accumulated result */
+ }
+ }
+ }
}
static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
- const char *e, int tr) {
- lua_State *L = ms->L;
- switch (tr) {
- case LUA_TFUNCTION: {
- int n;
- lua_pushvalue(L, 3);
- n = push_captures(ms, s, e);
- lua_call(L, n, 1);
- break;
- }
- case LUA_TTABLE: {
- push_onecapture(ms, 0, s, e);
- lua_gettable(L, 3);
- break;
- }
- default: { /* LUA_TNUMBER or LUA_TSTRING */
- add_s(ms, b, s, e);
- return;
- }
- }
- if (!lua_toboolean(L, -1)) { /* nil or false? */
- lua_pop(L, 1);
- lua_pushlstring(L, s, e - s); /* keep original text */
- }
- else if (!lua_isstring(L, -1))
- luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
- luaL_addvalue(b); /* add result to accumulator */
+ const char *e, int tr) {
+ lua_State *L = ms->L;
+ switch (tr) {
+ case LUA_TFUNCTION: {
+ int n;
+ lua_pushvalue(L, 3);
+ n = push_captures(ms, s, e);
+ lua_call(L, n, 1);
+ break;
+ }
+ case LUA_TTABLE: {
+ push_onecapture(ms, 0, s, e);
+ lua_gettable(L, 3);
+ break;
+ }
+ default: { /* LUA_TNUMBER or LUA_TSTRING */
+ add_s(ms, b, s, e);
+ return;
+ }
+ }
+ if (!lua_toboolean(L, -1)) { /* nil or false? */
+ lua_pop(L, 1);
+ lua_pushlstring(L, s, e - s); /* keep original text */
+ }
+ else if (!lua_isstring(L, -1))
+ luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
+ luaL_addvalue(b); /* add result to accumulator */
}
static int str_gsub (lua_State *L) {
- size_t srcl, lp;
- const char *src = luaL_checklstring(L, 1, &srcl);
- const char *p = luaL_checklstring(L, 2, &lp);
- int tr = lua_type(L, 3);
- size_t max_s = luaL_optinteger(L, 4, srcl+1);
- int anchor = (*p == '^');
- size_t n = 0;
- MatchState ms;
- luaL_Buffer b;
- luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
- tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
- "string/function/table expected");
- luaL_buffinit(L, &b);
- if (anchor) {
- p++; lp--; /* skip anchor character */
- }
- ms.L = L;
- ms.matchdepth = MAXCCALLS;
- ms.src_init = src;
- ms.src_end = src+srcl;
- ms.p_end = p + lp;
- while (n < max_s) {
- const char *e;
- ms.level = 0;
- lua_assert(ms.matchdepth == MAXCCALLS);
- e = match(&ms, src, p);
- if (e) {
- n++;
- add_value(&ms, &b, src, e, tr);
- }
- if (e && e>src) /* non empty match? */
- src = e; /* skip it */
- else if (src < ms.src_end)
- luaL_addchar(&b, *src++);
- else break;
- if (anchor) break;
- }
- luaL_addlstring(&b, src, ms.src_end-src);
- luaL_pushresult(&b);
- lua_pushinteger(L, n); /* number of substitutions */
- return 2;
+ size_t srcl, lp;
+ const char *src = luaL_checklstring(L, 1, &srcl);
+ const char *p = luaL_checklstring(L, 2, &lp);
+ int tr = lua_type(L, 3);
+ size_t max_s = luaL_optinteger(L, 4, srcl+1);
+ int anchor = (*p == '^');
+ size_t n = 0;
+ MatchState ms;
+ luaL_Buffer b;
+ luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
+ tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
+ "string/function/table expected");
+ luaL_buffinit(L, &b);
+ if (anchor) {
+ p++; lp--; /* skip anchor character */
+ }
+ ms.L = L;
+ ms.matchdepth = MAXCCALLS;
+ ms.src_init = src;
+ ms.src_end = src+srcl;
+ ms.p_end = p + lp;
+ while (n < max_s) {
+ const char *e;
+ ms.level = 0;
+ lua_assert(ms.matchdepth == MAXCCALLS);
+ e = match(&ms, src, p);
+ if (e) {
+ n++;
+ add_value(&ms, &b, src, e, tr);
+ }
+ if (e && e>src) /* non empty match? */
+ src = e; /* skip it */
+ else if (src < ms.src_end)
+ luaL_addchar(&b, *src++);
+ else break;
+ if (anchor) break;
+ }
+ luaL_addlstring(&b, src, ms.src_end-src);
+ luaL_pushresult(&b);
+ lua_pushinteger(L, n); /* number of substitutions */
+ return 2;
}
/* }====================================================== */
@@ -791,19 +791,19 @@ static int str_gsub (lua_State *L) {
** 'string.format'; LUA_INTFRM_T is the integer type corresponding to
** the previous length
*/
-#if !defined(LUA_INTFRMLEN) /* { */
+#if !defined(LUA_INTFRMLEN) /* { */
#if defined(LUA_USE_LONGLONG)
-#define LUA_INTFRMLEN "ll"
-#define LUA_INTFRM_T long long
+#define LUA_INTFRMLEN "ll"
+#define LUA_INTFRM_T long long
#else
-#define LUA_INTFRMLEN "l"
-#define LUA_INTFRM_T long
+#define LUA_INTFRMLEN "l"
+#define LUA_INTFRM_T long
#endif
-#endif /* } */
+#endif /* } */
/*
@@ -813,66 +813,66 @@ static int str_gsub (lua_State *L) {
*/
#if !defined(LUA_FLTFRMLEN)
-#define LUA_FLTFRMLEN ""
-#define LUA_FLTFRM_T double
+#define LUA_FLTFRMLEN ""
+#define LUA_FLTFRM_T double
#endif
/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
-#define MAX_ITEM 512
+#define MAX_ITEM 512
/* valid flags in a format specification */
-#define FLAGS "-+ #0"
+#define FLAGS "-+ #0"
/*
** maximum size of each format specification (such as '%-099.99d')
** (+10 accounts for %99.99x plus margin of error)
*/
-#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
+#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
- size_t l;
- const char *s = luaL_checklstring(L, arg, &l);
- luaL_addchar(b, '"');
- while (l--) {
- if (*s == '"' || *s == '\\' || *s == '\n') {
- luaL_addchar(b, '\\');
- luaL_addchar(b, *s);
- }
- else if (*s == '\0' || iscntrl(uchar(*s))) {
- char buff[10];
- if (!isdigit(uchar(*(s+1))))
- sprintf(buff, "\\%d", (int)uchar(*s));
- else
- sprintf(buff, "\\%03d", (int)uchar(*s));
- luaL_addstring(b, buff);
- }
- else
- luaL_addchar(b, *s);
- s++;
- }
- luaL_addchar(b, '"');
+ size_t l;
+ const char *s = luaL_checklstring(L, arg, &l);
+ luaL_addchar(b, '"');
+ while (l--) {
+ if (*s == '"' || *s == '\\' || *s == '\n') {
+ luaL_addchar(b, '\\');
+ luaL_addchar(b, *s);
+ }
+ else if (*s == '\0' || iscntrl(uchar(*s))) {
+ char buff[10];
+ if (!isdigit(uchar(*(s+1))))
+ sprintf(buff, "\\%d", (int)uchar(*s));
+ else
+ sprintf(buff, "\\%03d", (int)uchar(*s));
+ luaL_addstring(b, buff);
+ }
+ else
+ luaL_addchar(b, *s);
+ s++;
+ }
+ luaL_addchar(b, '"');
}
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
- const char *p = strfrmt;
- while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
- if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))
- luaL_error(L, "invalid format (repeated flags)");
- if (isdigit(uchar(*p))) p++; /* skip width */
- if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
- if (*p == '.') {
- p++;
- if (isdigit(uchar(*p))) p++; /* skip precision */
- if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
- }
- if (isdigit(uchar(*p)))
- luaL_error(L, "invalid format (width or precision too long)");
- *(form++) = '%';
- memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char));
- form += p - strfrmt + 1;
- *form = '\0';
- return p;
+ const char *p = strfrmt;
+ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
+ if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))
+ luaL_error(L, "invalid format (repeated flags)");
+ if (isdigit(uchar(*p))) p++; /* skip width */
+ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
+ if (*p == '.') {
+ p++;
+ if (isdigit(uchar(*p))) p++; /* skip precision */
+ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
+ }
+ if (isdigit(uchar(*p)))
+ luaL_error(L, "invalid format (width or precision too long)");
+ *(form++) = '%';
+ memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char));
+ form += p - strfrmt + 1;
+ *form = '\0';
+ return p;
}
@@ -880,131 +880,131 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
** add length modifier into formats
*/
static void addlenmod (char *form, const char *lenmod) {
- size_t l = strlen(form);
- size_t lm = strlen(lenmod);
- char spec = form[l - 1];
- strcpy(form + l - 1, lenmod);
- form[l + lm - 1] = spec;
- form[l + lm] = '\0';
+ size_t l = strlen(form);
+ size_t lm = strlen(lenmod);
+ char spec = form[l - 1];
+ strcpy(form + l - 1, lenmod);
+ form[l + lm - 1] = spec;
+ form[l + lm] = '\0';
}
static int str_format (lua_State *L) {
- int top = lua_gettop(L);
- int arg = 1;
- size_t sfl;
- const char *strfrmt = luaL_checklstring(L, arg, &sfl);
- const char *strfrmt_end = strfrmt+sfl;
- luaL_Buffer b;
- luaL_buffinit(L, &b);
- while (strfrmt < strfrmt_end) {
- if (*strfrmt != L_ESC)
- luaL_addchar(&b, *strfrmt++);
- else if (*++strfrmt == L_ESC)
- luaL_addchar(&b, *strfrmt++); /* %% */
- else { /* format item */
- char form[MAX_FORMAT]; /* to store the format (`%...') */
- char *buff = luaL_prepbuffsize(&b, MAX_ITEM); /* to put formatted item */
- int nb = 0; /* number of bytes in added item */
- if (++arg > top)
- luaL_argerror(L, arg, "no value");
- strfrmt = scanformat(L, strfrmt, form);
- switch (*strfrmt++) {
- case 'c': {
- nb = sprintf(buff, form, luaL_checkint(L, arg));
- break;
- }
- case 'd': case 'i': {
- lua_Number n = luaL_checknumber(L, arg);
- LUA_INTFRM_T ni = (LUA_INTFRM_T)n;
- lua_Number diff = n - (lua_Number)ni;
- luaL_argcheck(L, -1 < diff && diff < 1, arg,
- "not a number in proper range");
- addlenmod(form, LUA_INTFRMLEN);
- nb = sprintf(buff, form, ni);
- break;
- }
- case 'o': case 'u': case 'x': case 'X': {
- lua_Number n = luaL_checknumber(L, arg);
- unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n;
- lua_Number diff = n - (lua_Number)ni;
- luaL_argcheck(L, -1 < diff && diff < 1, arg,
- "not a non-negative number in proper range");
- addlenmod(form, LUA_INTFRMLEN);
- nb = sprintf(buff, form, ni);
- break;
- }
- case 'e': case 'E': case 'f':
+ int top = lua_gettop(L);
+ int arg = 1;
+ size_t sfl;
+ const char *strfrmt = luaL_checklstring(L, arg, &sfl);
+ const char *strfrmt_end = strfrmt+sfl;
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ while (strfrmt < strfrmt_end) {
+ if (*strfrmt != L_ESC)
+ luaL_addchar(&b, *strfrmt++);
+ else if (*++strfrmt == L_ESC)
+ luaL_addchar(&b, *strfrmt++); /* %% */
+ else { /* format item */
+ char form[MAX_FORMAT]; /* to store the format (`%...') */
+ char *buff = luaL_prepbuffsize(&b, MAX_ITEM); /* to put formatted item */
+ int nb = 0; /* number of bytes in added item */
+ if (++arg > top)
+ luaL_argerror(L, arg, "no value");
+ strfrmt = scanformat(L, strfrmt, form);
+ switch (*strfrmt++) {
+ case 'c': {
+ nb = sprintf(buff, form, luaL_checkint(L, arg));
+ break;
+ }
+ case 'd': case 'i': {
+ lua_Number n = luaL_checknumber(L, arg);
+ LUA_INTFRM_T ni = (LUA_INTFRM_T)n;
+ lua_Number diff = n - (lua_Number)ni;
+ luaL_argcheck(L, -1 < diff && diff < 1, arg,
+ "not a number in proper range");
+ addlenmod(form, LUA_INTFRMLEN);
+ nb = sprintf(buff, form, ni);
+ break;
+ }
+ case 'o': case 'u': case 'x': case 'X': {
+ lua_Number n = luaL_checknumber(L, arg);
+ unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n;
+ lua_Number diff = n - (lua_Number)ni;
+ luaL_argcheck(L, -1 < diff && diff < 1, arg,
+ "not a non-negative number in proper range");
+ addlenmod(form, LUA_INTFRMLEN);
+ nb = sprintf(buff, form, ni);
+ break;
+ }
+ case 'e': case 'E': case 'f':
#if defined(LUA_USE_AFORMAT)
- case 'a': case 'A':
+ case 'a': case 'A':
#endif
- case 'g': case 'G': {
- addlenmod(form, LUA_FLTFRMLEN);
- nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
- break;
- }
- case 'q': {
- addquoted(L, &b, arg);
- break;
- }
- case 's': {
- size_t l;
- const char *s = luaL_tolstring(L, arg, &l);
- if (!strchr(form, '.') && l >= 100) {
- /* no precision and string is too long to be formatted;
- keep original string */
- luaL_addvalue(&b);
- break;
- }
- else {
- nb = sprintf(buff, form, s);
- lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
- break;
- }
- }
- default: { /* also treat cases `pnLlh' */
- return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
- LUA_QL("format"), *(strfrmt - 1));
- }
- }
- luaL_addsize(&b, nb);
- }
- }
- luaL_pushresult(&b);
- return 1;
+ case 'g': case 'G': {
+ addlenmod(form, LUA_FLTFRMLEN);
+ nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
+ break;
+ }
+ case 'q': {
+ addquoted(L, &b, arg);
+ break;
+ }
+ case 's': {
+ size_t l;
+ const char *s = luaL_tolstring(L, arg, &l);
+ if (!strchr(form, '.') && l >= 100) {
+ /* no precision and string is too long to be formatted;
+ keep original string */
+ luaL_addvalue(&b);
+ break;
+ }
+ else {
+ nb = sprintf(buff, form, s);
+ lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ break;
+ }
+ }
+ default: { /* also treat cases `pnLlh' */
+ return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
+ LUA_QL("format"), *(strfrmt - 1));
+ }
+ }
+ luaL_addsize(&b, nb);
+ }
+ }
+ luaL_pushresult(&b);
+ return 1;
}
/* }====================================================== */
static const luaL_Reg strlib[] = {
- {"byte", str_byte},
- {"char", str_char},
- {"dump", str_dump},
- {"find", str_find},
- {"format", str_format},
- {"gmatch", gmatch},
- {"gsub", str_gsub},
- {"len", str_len},
- {"lower", str_lower},
- {"match", str_match},
- {"rep", str_rep},
- {"reverse", str_reverse},
- {"sub", str_sub},
- {"upper", str_upper},
- {NULL, NULL}
+ {"byte", str_byte},
+ {"char", str_char},
+ {"dump", str_dump},
+ {"find", str_find},
+ {"format", str_format},
+ {"gmatch", gmatch},
+ {"gsub", str_gsub},
+ {"len", str_len},
+ {"lower", str_lower},
+ {"match", str_match},
+ {"rep", str_rep},
+ {"reverse", str_reverse},
+ {"sub", str_sub},
+ {"upper", str_upper},
+ {NULL, NULL}
};
static void createmetatable (lua_State *L) {
- lua_createtable(L, 0, 1); /* table to be metatable for strings */
- lua_pushliteral(L, ""); /* dummy string */
- lua_pushvalue(L, -2); /* copy table */
- lua_setmetatable(L, -2); /* set table as metatable for strings */
- lua_pop(L, 1); /* pop dummy string */
- lua_pushvalue(L, -2); /* get string library */
- lua_setfield(L, -2, "__index"); /* metatable.__index = string */
- lua_pop(L, 1); /* pop metatable */
+ lua_createtable(L, 0, 1); /* table to be metatable for strings */
+ lua_pushliteral(L, ""); /* dummy string */
+ lua_pushvalue(L, -2); /* copy table */
+ lua_setmetatable(L, -2); /* set table as metatable for strings */
+ lua_pop(L, 1); /* pop dummy string */
+ lua_pushvalue(L, -2); /* get string library */
+ lua_setfield(L, -2, "__index"); /* metatable.__index = string */
+ lua_pop(L, 1); /* pop metatable */
}
@@ -1012,8 +1012,7 @@ static void createmetatable (lua_State *L) {
** Open string library
*/
LUAMOD_API int luaopen_string (lua_State *L) {
- luaL_newlib(L, strlib);
- createmetatable(L);
- return 1;
+ luaL_newlib(L, strlib);
+ createmetatable(L);
+ return 1;
}
-
diff --git a/src/lib/lua/ltable.c b/src/lib/lua/ltable.c
index 420391fc745..dac9c074b65 100644
--- a/src/lib/lua/ltable.c
+++ b/src/lib/lua/ltable.c
@@ -40,37 +40,37 @@
** max size of array part is 2^MAXBITS
*/
#if LUAI_BITSINT >= 32
-#define MAXBITS 30
+#define MAXBITS 30
#else
-#define MAXBITS (LUAI_BITSINT-2)
+#define MAXBITS (LUAI_BITSINT-2)
#endif
-#define MAXASIZE (1 << MAXBITS)
+#define MAXASIZE (1 << MAXBITS)
-#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
+#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
-#define hashstr(t,str) hashpow2(t, (str)->tsv.hash)
-#define hashboolean(t,p) hashpow2(t, p)
+#define hashstr(t,str) hashpow2(t, (str)->tsv.hash)
+#define hashboolean(t,p) hashpow2(t, p)
/*
** for some types, it is better to avoid modulus by power of 2, as
** they tend to have many 2 factors.
*/
-#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
+#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
-#define hashpointer(t,p) hashmod(t, IntPoint(p))
+#define hashpointer(t,p) hashmod(t, IntPoint(p))
-#define dummynode (&dummynode_)
+#define dummynode (&dummynode_)
-#define isdummy(n) ((n) == dummynode)
+#define isdummy(n) ((n) == dummynode)
static const Node dummynode_ = {
- {NILCONSTANT}, /* value */
- {{NILCONSTANT, NULL}} /* key */
+ {NILCONSTANT}, /* value */
+ {{NILCONSTANT, NULL}} /* key */
};
@@ -78,14 +78,14 @@ static const Node dummynode_ = {
** hash for lua_Numbers
*/
static Node *hashnum (const Table *t, lua_Number n) {
- int i;
- luai_hashnum(i, n);
- if (i < 0) {
- if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
- i = 0; /* handle INT_MIN */
- i = -i; /* must be a positive value */
- }
- return hashmod(t, i);
+ int i;
+ luai_hashnum(i, n);
+ if (i < 0) {
+ if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
+ i = 0; /* handle INT_MIN */
+ i = -i; /* must be a positive value */
+ }
+ return hashmod(t, i);
}
@@ -95,28 +95,28 @@ static Node *hashnum (const Table *t, lua_Number n) {
** of its hash value)
*/
static Node *mainposition (const Table *t, const TValue *key) {
- switch (ttype(key)) {
- case LUA_TNUMBER:
- return hashnum(t, nvalue(key));
- case LUA_TLNGSTR: {
- TString *s = rawtsvalue(key);
- if (s->tsv.extra == 0) { /* no hash? */
- s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash);
- s->tsv.extra = 1; /* now it has its hash */
- }
- return hashstr(t, rawtsvalue(key));
- }
- case LUA_TSHRSTR:
- return hashstr(t, rawtsvalue(key));
- case LUA_TBOOLEAN:
- return hashboolean(t, bvalue(key));
- case LUA_TLIGHTUSERDATA:
- return hashpointer(t, pvalue(key));
- case LUA_TLCF:
- return hashpointer(t, fvalue(key));
- default:
- return hashpointer(t, gcvalue(key));
- }
+ switch (ttype(key)) {
+ case LUA_TNUMBER:
+ return hashnum(t, nvalue(key));
+ case LUA_TLNGSTR: {
+ TString *s = rawtsvalue(key);
+ if (s->tsv.extra == 0) { /* no hash? */
+ s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash);
+ s->tsv.extra = 1; /* now it has its hash */
+ }
+ return hashstr(t, rawtsvalue(key));
+ }
+ case LUA_TSHRSTR:
+ return hashstr(t, rawtsvalue(key));
+ case LUA_TBOOLEAN:
+ return hashboolean(t, bvalue(key));
+ case LUA_TLIGHTUSERDATA:
+ return hashpointer(t, pvalue(key));
+ case LUA_TLCF:
+ return hashpointer(t, fvalue(key));
+ default:
+ return hashpointer(t, gcvalue(key));
+ }
}
@@ -125,14 +125,14 @@ static Node *mainposition (const Table *t, const TValue *key) {
** the array part of the table, -1 otherwise.
*/
static int arrayindex (const TValue *key) {
- if (ttisnumber(key)) {
- lua_Number n = nvalue(key);
- int k;
- lua_number2int(k, n);
- if (luai_numeq(cast_num(k), n))
- return k;
- }
- return -1; /* `key' did not match some condition */
+ if (ttisnumber(key)) {
+ lua_Number n = nvalue(key);
+ int k;
+ lua_number2int(k, n);
+ if (luai_numeq(cast_num(k), n))
+ return k;
+ }
+ return -1; /* `key' did not match some condition */
}
@@ -142,47 +142,47 @@ static int arrayindex (const TValue *key) {
** beginning of a traversal is signaled by -1.
*/
static int findindex (lua_State *L, Table *t, StkId key) {
- int i;
- if (ttisnil(key)) return -1; /* first iteration */
- i = arrayindex(key);
- if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
- return i-1; /* yes; that's the index (corrected to C) */
- else {
- Node *n = mainposition(t, key);
- for (;;) { /* check whether `key' is somewhere in the chain */
- /* key may be dead already, but it is ok to use it in `next' */
- if (luaV_rawequalobj(gkey(n), key) ||
- (ttisdeadkey(gkey(n)) && iscollectable(key) &&
- deadvalue(gkey(n)) == gcvalue(key))) {
- i = cast_int(n - gnode(t, 0)); /* key index in hash table */
- /* hash elements are numbered after array ones */
- return i + t->sizearray;
- }
- else n = gnext(n);
- if (n == NULL)
- luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
- }
- }
+ int i;
+ if (ttisnil(key)) return -1; /* first iteration */
+ i = arrayindex(key);
+ if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
+ return i-1; /* yes; that's the index (corrected to C) */
+ else {
+ Node *n = mainposition(t, key);
+ for (;;) { /* check whether `key' is somewhere in the chain */
+ /* key may be dead already, but it is ok to use it in `next' */
+ if (luaV_rawequalobj(gkey(n), key) ||
+ (ttisdeadkey(gkey(n)) && iscollectable(key) &&
+ deadvalue(gkey(n)) == gcvalue(key))) {
+ i = cast_int(n - gnode(t, 0)); /* key index in hash table */
+ /* hash elements are numbered after array ones */
+ return i + t->sizearray;
+ }
+ else n = gnext(n);
+ if (n == NULL)
+ luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
+ }
+ }
}
int luaH_next (lua_State *L, Table *t, StkId key) {
- int i = findindex(L, t, key); /* find original element */
- for (i++; i < t->sizearray; i++) { /* try first array part */
- if (!ttisnil(&t->array[i])) { /* a non-nil value? */
- setnvalue(key, cast_num(i+1));
- setobj2s(L, key+1, &t->array[i]);
- return 1;
- }
- }
- for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
- if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
- setobj2s(L, key, gkey(gnode(t, i)));
- setobj2s(L, key+1, gval(gnode(t, i)));
- return 1;
- }
- }
- return 0; /* no more elements */
+ int i = findindex(L, t, key); /* find original element */
+ for (i++; i < t->sizearray; i++) { /* try first array part */
+ if (!ttisnil(&t->array[i])) { /* a non-nil value? */
+ setnvalue(key, cast_num(i+1));
+ setobj2s(L, key+1, &t->array[i]);
+ return 1;
+ }
+ }
+ for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
+ if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
+ setobj2s(L, key, gkey(gnode(t, i)));
+ setobj2s(L, key+1, gval(gnode(t, i)));
+ return 1;
+ }
+ }
+ return 0; /* no more elements */
}
@@ -194,168 +194,168 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
static int computesizes (int nums[], int *narray) {
- int i;
- int twotoi; /* 2^i */
- int a = 0; /* number of elements smaller than 2^i */
- int na = 0; /* number of elements to go to array part */
- int n = 0; /* optimal size for array part */
- for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
- if (nums[i] > 0) {
- a += nums[i];
- if (a > twotoi/2) { /* more than half elements present? */
- n = twotoi; /* optimal size (till now) */
- na = a; /* all elements smaller than n will go to array part */
- }
- }
- if (a == *narray) break; /* all elements already counted */
- }
- *narray = n;
- lua_assert(*narray/2 <= na && na <= *narray);
- return na;
+ int i;
+ int twotoi; /* 2^i */
+ int a = 0; /* number of elements smaller than 2^i */
+ int na = 0; /* number of elements to go to array part */
+ int n = 0; /* optimal size for array part */
+ for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
+ if (nums[i] > 0) {
+ a += nums[i];
+ if (a > twotoi/2) { /* more than half elements present? */
+ n = twotoi; /* optimal size (till now) */
+ na = a; /* all elements smaller than n will go to array part */
+ }
+ }
+ if (a == *narray) break; /* all elements already counted */
+ }
+ *narray = n;
+ lua_assert(*narray/2 <= na && na <= *narray);
+ return na;
}
static int countint (const TValue *key, int *nums) {
- int k = arrayindex(key);
- if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
- nums[luaO_ceillog2(k)]++; /* count as such */
- return 1;
- }
- else
- return 0;
+ int k = arrayindex(key);
+ if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
+ nums[luaO_ceillog2(k)]++; /* count as such */
+ return 1;
+ }
+ else
+ return 0;
}
static int numusearray (const Table *t, int *nums) {
- int lg;
- int ttlg; /* 2^lg */
- int ause = 0; /* summation of `nums' */
- int i = 1; /* count to traverse all array keys */
- for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */
- int lc = 0; /* counter */
- int lim = ttlg;
- if (lim > t->sizearray) {
- lim = t->sizearray; /* adjust upper limit */
- if (i > lim)
- break; /* no more elements to count */
- }
- /* count elements in range (2^(lg-1), 2^lg] */
- for (; i <= lim; i++) {
- if (!ttisnil(&t->array[i-1]))
- lc++;
- }
- nums[lg] += lc;
- ause += lc;
- }
- return ause;
+ int lg;
+ int ttlg; /* 2^lg */
+ int ause = 0; /* summation of `nums' */
+ int i = 1; /* count to traverse all array keys */
+ for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */
+ int lc = 0; /* counter */
+ int lim = ttlg;
+ if (lim > t->sizearray) {
+ lim = t->sizearray; /* adjust upper limit */
+ if (i > lim)
+ break; /* no more elements to count */
+ }
+ /* count elements in range (2^(lg-1), 2^lg] */
+ for (; i <= lim; i++) {
+ if (!ttisnil(&t->array[i-1]))
+ lc++;
+ }
+ nums[lg] += lc;
+ ause += lc;
+ }
+ return ause;
}
static int numusehash (const Table *t, int *nums, int *pnasize) {
- int totaluse = 0; /* total number of elements */
- int ause = 0; /* summation of `nums' */
- int i = sizenode(t);
- while (i--) {
- Node *n = &t->node[i];
- if (!ttisnil(gval(n))) {
- ause += countint(gkey(n), nums);
- totaluse++;
- }
- }
- *pnasize += ause;
- return totaluse;
+ int totaluse = 0; /* total number of elements */
+ int ause = 0; /* summation of `nums' */
+ int i = sizenode(t);
+ while (i--) {
+ Node *n = &t->node[i];
+ if (!ttisnil(gval(n))) {
+ ause += countint(gkey(n), nums);
+ totaluse++;
+ }
+ }
+ *pnasize += ause;
+ return totaluse;
}
static void setarrayvector (lua_State *L, Table *t, int size) {
- int i;
- luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
- for (i=t->sizearray; i<size; i++)
- setnilvalue(&t->array[i]);
- t->sizearray = size;
+ int i;
+ luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
+ for (i=t->sizearray; i<size; i++)
+ setnilvalue(&t->array[i]);
+ t->sizearray = size;
}
static void setnodevector (lua_State *L, Table *t, int size) {
- int lsize;
- if (size == 0) { /* no elements to hash part? */
- t->node = cast(Node *, dummynode); /* use common `dummynode' */
- lsize = 0;
- }
- else {
- int i;
- lsize = luaO_ceillog2(size);
- if (lsize > MAXBITS)
- luaG_runerror(L, "table overflow");
- size = twoto(lsize);
- t->node = luaM_newvector(L, size, Node);
- for (i=0; i<size; i++) {
- Node *n = gnode(t, i);
- gnext(n) = NULL;
- setnilvalue(gkey(n));
- setnilvalue(gval(n));
- }
- }
- t->lsizenode = cast_byte(lsize);
- t->lastfree = gnode(t, size); /* all positions are free */
+ int lsize;
+ if (size == 0) { /* no elements to hash part? */
+ t->node = cast(Node *, dummynode); /* use common `dummynode' */
+ lsize = 0;
+ }
+ else {
+ int i;
+ lsize = luaO_ceillog2(size);
+ if (lsize > MAXBITS)
+ luaG_runerror(L, "table overflow");
+ size = twoto(lsize);
+ t->node = luaM_newvector(L, size, Node);
+ for (i=0; i<size; i++) {
+ Node *n = gnode(t, i);
+ gnext(n) = NULL;
+ setnilvalue(gkey(n));
+ setnilvalue(gval(n));
+ }
+ }
+ t->lsizenode = cast_byte(lsize);
+ t->lastfree = gnode(t, size); /* all positions are free */
}
void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
- int i;
- int oldasize = t->sizearray;
- int oldhsize = t->lsizenode;
- Node *nold = t->node; /* save old hash ... */
- if (nasize > oldasize) /* array part must grow? */
- setarrayvector(L, t, nasize);
- /* create new hash part with appropriate size */
- setnodevector(L, t, nhsize);
- if (nasize < oldasize) { /* array part must shrink? */
- t->sizearray = nasize;
- /* re-insert elements from vanishing slice */
- for (i=nasize; i<oldasize; i++) {
- if (!ttisnil(&t->array[i]))
- luaH_setint(L, t, i + 1, &t->array[i]);
- }
- /* shrink array */
- luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
- }
- /* re-insert elements from hash part */
- for (i = twoto(oldhsize) - 1; i >= 0; i--) {
- Node *old = nold+i;
- if (!ttisnil(gval(old))) {
- /* doesn't need barrier/invalidate cache, as entry was
- already present in the table */
- setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
- }
- }
- if (!isdummy(nold))
- luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
+ int i;
+ int oldasize = t->sizearray;
+ int oldhsize = t->lsizenode;
+ Node *nold = t->node; /* save old hash ... */
+ if (nasize > oldasize) /* array part must grow? */
+ setarrayvector(L, t, nasize);
+ /* create new hash part with appropriate size */
+ setnodevector(L, t, nhsize);
+ if (nasize < oldasize) { /* array part must shrink? */
+ t->sizearray = nasize;
+ /* re-insert elements from vanishing slice */
+ for (i=nasize; i<oldasize; i++) {
+ if (!ttisnil(&t->array[i]))
+ luaH_setint(L, t, i + 1, &t->array[i]);
+ }
+ /* shrink array */
+ luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
+ }
+ /* re-insert elements from hash part */
+ for (i = twoto(oldhsize) - 1; i >= 0; i--) {
+ Node *old = nold+i;
+ if (!ttisnil(gval(old))) {
+ /* doesn't need barrier/invalidate cache, as entry was
+ already present in the table */
+ setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
+ }
+ }
+ if (!isdummy(nold))
+ luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
}
void luaH_resizearray (lua_State *L, Table *t, int nasize) {
- int nsize = isdummy(t->node) ? 0 : sizenode(t);
- luaH_resize(L, t, nasize, nsize);
+ int nsize = isdummy(t->node) ? 0 : sizenode(t);
+ luaH_resize(L, t, nasize, nsize);
}
static void rehash (lua_State *L, Table *t, const TValue *ek) {
- int nasize, na;
- int nums[MAXBITS+1]; /* nums[i] = number of keys with 2^(i-1) < k <= 2^i */
- int i;
- int totaluse;
- for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */
- nasize = numusearray(t, nums); /* count keys in array part */
- totaluse = nasize; /* all those keys are integer keys */
- totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
- /* count extra key */
- nasize += countint(ek, nums);
- totaluse++;
- /* compute new size for array part */
- na = computesizes(nums, &nasize);
- /* resize the table to new computed sizes */
- luaH_resize(L, t, nasize, totaluse - na);
+ int nasize, na;
+ int nums[MAXBITS+1]; /* nums[i] = number of keys with 2^(i-1) < k <= 2^i */
+ int i;
+ int totaluse;
+ for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */
+ nasize = numusearray(t, nums); /* count keys in array part */
+ totaluse = nasize; /* all those keys are integer keys */
+ totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
+ /* count extra key */
+ nasize += countint(ek, nums);
+ totaluse++;
+ /* compute new size for array part */
+ na = computesizes(nums, &nasize);
+ /* resize the table to new computed sizes */
+ luaH_resize(L, t, nasize, totaluse - na);
}
@@ -366,31 +366,31 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
Table *luaH_new (lua_State *L) {
- Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
- t->metatable = NULL;
- t->flags = cast_byte(~0);
- t->array = NULL;
- t->sizearray = 0;
- setnodevector(L, t, 0);
- return t;
+ Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
+ t->metatable = NULL;
+ t->flags = cast_byte(~0);
+ t->array = NULL;
+ t->sizearray = 0;
+ setnodevector(L, t, 0);
+ return t;
}
void luaH_free (lua_State *L, Table *t) {
- if (!isdummy(t->node))
- luaM_freearray(L, t->node, cast(size_t, sizenode(t)));
- luaM_freearray(L, t->array, t->sizearray);
- luaM_free(L, t);
+ if (!isdummy(t->node))
+ luaM_freearray(L, t->node, cast(size_t, sizenode(t)));
+ luaM_freearray(L, t->array, t->sizearray);
+ luaM_free(L, t);
}
static Node *getfreepos (Table *t) {
- while (t->lastfree > t->node) {
- t->lastfree--;
- if (ttisnil(gkey(t->lastfree)))
- return t->lastfree;
- }
- return NULL; /* could not find a free place */
+ while (t->lastfree > t->node) {
+ t->lastfree--;
+ if (ttisnil(gkey(t->lastfree)))
+ return t->lastfree;
+ }
+ return NULL; /* could not find a free place */
}
@@ -403,40 +403,40 @@ static Node *getfreepos (Table *t) {
** position), new key goes to an empty position.
*/
TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
- Node *mp;
- if (ttisnil(key)) luaG_runerror(L, "table index is nil");
- else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
- luaG_runerror(L, "table index is NaN");
- mp = mainposition(t, key);
- if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
- Node *othern;
- Node *n = getfreepos(t); /* get a free place */
- if (n == NULL) { /* cannot find a free place? */
- rehash(L, t, key); /* grow table */
- /* whatever called 'newkey' take care of TM cache and GC barrier */
- return luaH_set(L, t, key); /* insert key into grown table */
- }
- lua_assert(!isdummy(n));
- othern = mainposition(t, gkey(mp));
- if (othern != mp) { /* is colliding node out of its main position? */
- /* yes; move colliding node into free position */
- while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
- gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
- *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
- gnext(mp) = NULL; /* now `mp' is free */
- setnilvalue(gval(mp));
- }
- else { /* colliding node is in its own main position */
- /* new node will go into free position */
- gnext(n) = gnext(mp); /* chain new position */
- gnext(mp) = n;
- mp = n;
- }
- }
- setobj2t(L, gkey(mp), key);
- luaC_barrierback(L, obj2gco(t), key);
- lua_assert(ttisnil(gval(mp)));
- return gval(mp);
+ Node *mp;
+ if (ttisnil(key)) luaG_runerror(L, "table index is nil");
+ else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
+ luaG_runerror(L, "table index is NaN");
+ mp = mainposition(t, key);
+ if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
+ Node *othern;
+ Node *n = getfreepos(t); /* get a free place */
+ if (n == NULL) { /* cannot find a free place? */
+ rehash(L, t, key); /* grow table */
+ /* whatever called 'newkey' take care of TM cache and GC barrier */
+ return luaH_set(L, t, key); /* insert key into grown table */
+ }
+ lua_assert(!isdummy(n));
+ othern = mainposition(t, gkey(mp));
+ if (othern != mp) { /* is colliding node out of its main position? */
+ /* yes; move colliding node into free position */
+ while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
+ gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
+ *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
+ gnext(mp) = NULL; /* now `mp' is free */
+ setnilvalue(gval(mp));
+ }
+ else { /* colliding node is in its own main position */
+ /* new node will go into free position */
+ gnext(n) = gnext(mp); /* chain new position */
+ gnext(mp) = n;
+ mp = n;
+ }
+ }
+ setobj2t(L, gkey(mp), key);
+ luaC_barrierback(L, obj2gco(t), key);
+ lua_assert(ttisnil(gval(mp)));
+ return gval(mp);
}
@@ -444,19 +444,19 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
** search function for integers
*/
const TValue *luaH_getint (Table *t, int key) {
- /* (1 <= key && key <= t->sizearray) */
- if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
- return &t->array[key-1];
- else {
- lua_Number nk = cast_num(key);
- Node *n = hashnum(t, nk);
- do { /* check whether `key' is somewhere in the chain */
- if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
- return gval(n); /* that's it */
- else n = gnext(n);
- } while (n);
- return luaO_nilobject;
- }
+ /* (1 <= key && key <= t->sizearray) */
+ if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
+ return &t->array[key-1];
+ else {
+ lua_Number nk = cast_num(key);
+ Node *n = hashnum(t, nk);
+ do { /* check whether `key' is somewhere in the chain */
+ if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
+ return gval(n); /* that's it */
+ else n = gnext(n);
+ } while (n);
+ return luaO_nilobject;
+ }
}
@@ -464,14 +464,14 @@ const TValue *luaH_getint (Table *t, int key) {
** search function for short strings
*/
const TValue *luaH_getstr (Table *t, TString *key) {
- Node *n = hashstr(t, key);
- lua_assert(key->tsv.tt == LUA_TSHRSTR);
- do { /* check whether `key' is somewhere in the chain */
- if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key))
- return gval(n); /* that's it */
- else n = gnext(n);
- } while (n);
- return luaO_nilobject;
+ Node *n = hashstr(t, key);
+ lua_assert(key->tsv.tt == LUA_TSHRSTR);
+ do { /* check whether `key' is somewhere in the chain */
+ if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key))
+ return gval(n); /* that's it */
+ else n = gnext(n);
+ } while (n);
+ return luaO_nilobject;
}
@@ -479,27 +479,27 @@ const TValue *luaH_getstr (Table *t, TString *key) {
** main search function
*/
const TValue *luaH_get (Table *t, const TValue *key) {
- switch (ttype(key)) {
- case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key));
- case LUA_TNIL: return luaO_nilobject;
- case LUA_TNUMBER: {
- int k;
- lua_Number n = nvalue(key);
- lua_number2int(k, n);
- if (luai_numeq(cast_num(k), n)) /* index is int? */
- return luaH_getint(t, k); /* use specialized version */
- /* else go through */
- }
- default: {
- Node *n = mainposition(t, key);
- do { /* check whether `key' is somewhere in the chain */
- if (luaV_rawequalobj(gkey(n), key))
- return gval(n); /* that's it */
- else n = gnext(n);
- } while (n);
- return luaO_nilobject;
- }
- }
+ switch (ttype(key)) {
+ case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key));
+ case LUA_TNIL: return luaO_nilobject;
+ case LUA_TNUMBER: {
+ int k;
+ lua_Number n = nvalue(key);
+ lua_number2int(k, n);
+ if (luai_numeq(cast_num(k), n)) /* index is int? */
+ return luaH_getint(t, k); /* use specialized version */
+ /* else go through */
+ }
+ default: {
+ Node *n = mainposition(t, key);
+ do { /* check whether `key' is somewhere in the chain */
+ if (luaV_rawequalobj(gkey(n), key))
+ return gval(n); /* that's it */
+ else n = gnext(n);
+ } while (n);
+ return luaO_nilobject;
+ }
+ }
}
@@ -508,48 +508,48 @@ const TValue *luaH_get (Table *t, const TValue *key) {
** barrier and invalidate the TM cache.
*/
TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
- const TValue *p = luaH_get(t, key);
- if (p != luaO_nilobject)
- return cast(TValue *, p);
- else return luaH_newkey(L, t, key);
+ const TValue *p = luaH_get(t, key);
+ if (p != luaO_nilobject)
+ return cast(TValue *, p);
+ else return luaH_newkey(L, t, key);
}
void luaH_setint (lua_State *L, Table *t, int key, TValue *value) {
- const TValue *p = luaH_getint(t, key);
- TValue *cell;
- if (p != luaO_nilobject)
- cell = cast(TValue *, p);
- else {
- TValue k;
- setnvalue(&k, cast_num(key));
- cell = luaH_newkey(L, t, &k);
- }
- setobj2t(L, cell, value);
+ const TValue *p = luaH_getint(t, key);
+ TValue *cell;
+ if (p != luaO_nilobject)
+ cell = cast(TValue *, p);
+ else {
+ TValue k;
+ setnvalue(&k, cast_num(key));
+ cell = luaH_newkey(L, t, &k);
+ }
+ setobj2t(L, cell, value);
}
static int unbound_search (Table *t, unsigned int j) {
- unsigned int i = j; /* i is zero or a present index */
- j++;
- /* find `i' and `j' such that i is present and j is not */
- while (!ttisnil(luaH_getint(t, j))) {
- i = j;
- j *= 2;
- if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
- /* table was built with bad purposes: resort to linear search */
- i = 1;
- while (!ttisnil(luaH_getint(t, i))) i++;
- return i - 1;
- }
- }
- /* now do a binary search between them */
- while (j - i > 1) {
- unsigned int m = (i+j)/2;
- if (ttisnil(luaH_getint(t, m))) j = m;
- else i = m;
- }
- return i;
+ unsigned int i = j; /* i is zero or a present index */
+ j++;
+ /* find `i' and `j' such that i is present and j is not */
+ while (!ttisnil(luaH_getint(t, j))) {
+ i = j;
+ j *= 2;
+ if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
+ /* table was built with bad purposes: resort to linear search */
+ i = 1;
+ while (!ttisnil(luaH_getint(t, i))) i++;
+ return i - 1;
+ }
+ }
+ /* now do a binary search between them */
+ while (j - i > 1) {
+ unsigned int m = (i+j)/2;
+ if (ttisnil(luaH_getint(t, m))) j = m;
+ else i = m;
+ }
+ return i;
}
@@ -558,21 +558,21 @@ static int unbound_search (Table *t, unsigned int j) {
** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
*/
int luaH_getn (Table *t) {
- unsigned int j = t->sizearray;
- if (j > 0 && ttisnil(&t->array[j - 1])) {
- /* there is a boundary in the array part: (binary) search for it */
- unsigned int i = 0;
- while (j - i > 1) {
- unsigned int m = (i+j)/2;
- if (ttisnil(&t->array[m - 1])) j = m;
- else i = m;
- }
- return i;
- }
- /* else must find a boundary in hash part */
- else if (isdummy(t->node)) /* hash part is empty? */
- return j; /* that is easy... */
- else return unbound_search(t, j);
+ unsigned int j = t->sizearray;
+ if (j > 0 && ttisnil(&t->array[j - 1])) {
+ /* there is a boundary in the array part: (binary) search for it */
+ unsigned int i = 0;
+ while (j - i > 1) {
+ unsigned int m = (i+j)/2;
+ if (ttisnil(&t->array[m - 1])) j = m;
+ else i = m;
+ }
+ return i;
+ }
+ /* else must find a boundary in hash part */
+ else if (isdummy(t->node)) /* hash part is empty? */
+ return j; /* that is easy... */
+ else return unbound_search(t, j);
}
@@ -580,7 +580,7 @@ int luaH_getn (Table *t) {
#if defined(LUA_DEBUG)
Node *luaH_mainposition (const Table *t, const TValue *key) {
- return mainposition(t, key);
+ return mainposition(t, key);
}
int luaH_isdummy (Node *n) { return isdummy(n); }
diff --git a/src/lib/lua/ltable.h b/src/lib/lua/ltable.h
index 2f6f5c2dc85..f4abd65a2cc 100644
--- a/src/lib/lua/ltable.h
+++ b/src/lib/lua/ltable.h
@@ -10,12 +10,12 @@
#include "lobject.h"
-#define gnode(t,i) (&(t)->node[i])
-#define gkey(n) (&(n)->i_key.tvk)
-#define gval(n) (&(n)->i_val)
-#define gnext(n) ((n)->i_key.nk.next)
+#define gnode(t,i) (&(t)->node[i])
+#define gkey(n) (&(n)->i_key.tvk)
+#define gval(n) (&(n)->i_val)
+#define gnext(n) ((n)->i_key.nk.next)
-#define invalidateTMcache(t) ((t)->flags = 0)
+#define invalidateTMcache(t) ((t)->flags = 0)
LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
diff --git a/src/lib/lua/ltablib.c b/src/lib/lua/ltablib.c
index ad798b4e2aa..1736846863f 100644
--- a/src/lib/lua/ltablib.c
+++ b/src/lib/lua/ltablib.c
@@ -16,97 +16,97 @@
#include "lualib.h"
-#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n))
+#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n))
#if defined(LUA_COMPAT_MAXN)
static int maxn (lua_State *L) {
- lua_Number max = 0;
- luaL_checktype(L, 1, LUA_TTABLE);
- lua_pushnil(L); /* first key */
- while (lua_next(L, 1)) {
- lua_pop(L, 1); /* remove value */
- if (lua_type(L, -1) == LUA_TNUMBER) {
- lua_Number v = lua_tonumber(L, -1);
- if (v > max) max = v;
- }
- }
- lua_pushnumber(L, max);
- return 1;
+ lua_Number max = 0;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_pushnil(L); /* first key */
+ while (lua_next(L, 1)) {
+ lua_pop(L, 1); /* remove value */
+ if (lua_type(L, -1) == LUA_TNUMBER) {
+ lua_Number v = lua_tonumber(L, -1);
+ if (v > max) max = v;
+ }
+ }
+ lua_pushnumber(L, max);
+ return 1;
}
#endif
static int tinsert (lua_State *L) {
- int e = aux_getn(L, 1) + 1; /* first empty element */
- int pos; /* where to insert new element */
- switch (lua_gettop(L)) {
- case 2: { /* called with only 2 arguments */
- pos = e; /* insert new element at the end */
- break;
- }
- case 3: {
- int i;
- pos = luaL_checkint(L, 2); /* 2nd argument is the position */
- luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
- for (i = e; i > pos; i--) { /* move up elements */
- lua_rawgeti(L, 1, i-1);
- lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
- }
- break;
- }
- default: {
- return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
- }
- }
- lua_rawseti(L, 1, pos); /* t[pos] = v */
- return 0;
+ int e = aux_getn(L, 1) + 1; /* first empty element */
+ int pos; /* where to insert new element */
+ switch (lua_gettop(L)) {
+ case 2: { /* called with only 2 arguments */
+ pos = e; /* insert new element at the end */
+ break;
+ }
+ case 3: {
+ int i;
+ pos = luaL_checkint(L, 2); /* 2nd argument is the position */
+ luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
+ for (i = e; i > pos; i--) { /* move up elements */
+ lua_rawgeti(L, 1, i-1);
+ lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
+ }
+ break;
+ }
+ default: {
+ return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
+ }
+ }
+ lua_rawseti(L, 1, pos); /* t[pos] = v */
+ return 0;
}
static int tremove (lua_State *L) {
- int size = aux_getn(L, 1);
- int pos = luaL_optint(L, 2, size);
- if (pos != size) /* validate 'pos' if given */
- luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
- lua_rawgeti(L, 1, pos); /* result = t[pos] */
- for ( ; pos < size; pos++) {
- lua_rawgeti(L, 1, pos+1);
- lua_rawseti(L, 1, pos); /* t[pos] = t[pos+1] */
- }
- lua_pushnil(L);
- lua_rawseti(L, 1, pos); /* t[pos] = nil */
- return 1;
+ int size = aux_getn(L, 1);
+ int pos = luaL_optint(L, 2, size);
+ if (pos != size) /* validate 'pos' if given */
+ luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
+ lua_rawgeti(L, 1, pos); /* result = t[pos] */
+ for ( ; pos < size; pos++) {
+ lua_rawgeti(L, 1, pos+1);
+ lua_rawseti(L, 1, pos); /* t[pos] = t[pos+1] */
+ }
+ lua_pushnil(L);
+ lua_rawseti(L, 1, pos); /* t[pos] = nil */
+ return 1;
}
static void addfield (lua_State *L, luaL_Buffer *b, int i) {
- lua_rawgeti(L, 1, i);
- if (!lua_isstring(L, -1))
- luaL_error(L, "invalid value (%s) at index %d in table for "
- LUA_QL("concat"), luaL_typename(L, -1), i);
- luaL_addvalue(b);
+ lua_rawgeti(L, 1, i);
+ if (!lua_isstring(L, -1))
+ luaL_error(L, "invalid value (%s) at index %d in table for "
+ LUA_QL("concat"), luaL_typename(L, -1), i);
+ luaL_addvalue(b);
}
static int tconcat (lua_State *L) {
- luaL_Buffer b;
- size_t lsep;
- int i, last;
- const char *sep = luaL_optlstring(L, 2, "", &lsep);
- luaL_checktype(L, 1, LUA_TTABLE);
- i = luaL_optint(L, 3, 1);
- last = luaL_opt(L, luaL_checkint, 4, luaL_len(L, 1));
- luaL_buffinit(L, &b);
- for (; i < last; i++) {
- addfield(L, &b, i);
- luaL_addlstring(&b, sep, lsep);
- }
- if (i == last) /* add last value (if interval was not empty) */
- addfield(L, &b, i);
- luaL_pushresult(&b);
- return 1;
+ luaL_Buffer b;
+ size_t lsep;
+ int i, last;
+ const char *sep = luaL_optlstring(L, 2, "", &lsep);
+ luaL_checktype(L, 1, LUA_TTABLE);
+ i = luaL_optint(L, 3, 1);
+ last = luaL_opt(L, luaL_checkint, 4, luaL_len(L, 1));
+ luaL_buffinit(L, &b);
+ for (; i < last; i++) {
+ addfield(L, &b, i);
+ luaL_addlstring(&b, sep, lsep);
+ }
+ if (i == last) /* add last value (if interval was not empty) */
+ addfield(L, &b, i);
+ luaL_pushresult(&b);
+ return 1;
}
@@ -117,35 +117,35 @@ static int tconcat (lua_State *L) {
*/
static int pack (lua_State *L) {
- int n = lua_gettop(L); /* number of elements to pack */
- lua_createtable(L, n, 1); /* create result table */
- lua_pushinteger(L, n);
- lua_setfield(L, -2, "n"); /* t.n = number of elements */
- if (n > 0) { /* at least one element? */
- int i;
- lua_pushvalue(L, 1);
- lua_rawseti(L, -2, 1); /* insert first element */
- lua_replace(L, 1); /* move table into index 1 */
- for (i = n; i >= 2; i--) /* assign other elements */
- lua_rawseti(L, 1, i);
- }
- return 1; /* return table */
+ int n = lua_gettop(L); /* number of elements to pack */
+ lua_createtable(L, n, 1); /* create result table */
+ lua_pushinteger(L, n);
+ lua_setfield(L, -2, "n"); /* t.n = number of elements */
+ if (n > 0) { /* at least one element? */
+ int i;
+ lua_pushvalue(L, 1);
+ lua_rawseti(L, -2, 1); /* insert first element */
+ lua_replace(L, 1); /* move table into index 1 */
+ for (i = n; i >= 2; i--) /* assign other elements */
+ lua_rawseti(L, 1, i);
+ }
+ return 1; /* return table */
}
static int unpack (lua_State *L) {
- int i, e, n;
- luaL_checktype(L, 1, LUA_TTABLE);
- i = luaL_optint(L, 2, 1);
- e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
- if (i > e) return 0; /* empty range */
- n = e - i + 1; /* number of elements */
- if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
- return luaL_error(L, "too many results to unpack");
- lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
- while (i++ < e) /* push arg[i + 1...e] */
- lua_rawgeti(L, 1, i);
- return n;
+ int i, e, n;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ i = luaL_optint(L, 2, 1);
+ e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
+ if (i > e) return 0; /* empty range */
+ n = e - i + 1; /* number of elements */
+ if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
+ return luaL_error(L, "too many results to unpack");
+ lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
+ while (i++ < e) /* push arg[i + 1...e] */
+ lua_rawgeti(L, 1, i);
+ return n;
}
/* }====================================================== */
@@ -162,122 +162,121 @@ static int unpack (lua_State *L) {
static void set2 (lua_State *L, int i, int j) {
- lua_rawseti(L, 1, i);
- lua_rawseti(L, 1, j);
+ lua_rawseti(L, 1, i);
+ lua_rawseti(L, 1, j);
}
static int sort_comp (lua_State *L, int a, int b) {
- if (!lua_isnil(L, 2)) { /* function? */
- int res;
- lua_pushvalue(L, 2);
- lua_pushvalue(L, a-1); /* -1 to compensate function */
- lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
- lua_call(L, 2, 1);
- res = lua_toboolean(L, -1);
- lua_pop(L, 1);
- return res;
- }
- else /* a < b? */
- return lua_compare(L, a, b, LUA_OPLT);
+ if (!lua_isnil(L, 2)) { /* function? */
+ int res;
+ lua_pushvalue(L, 2);
+ lua_pushvalue(L, a-1); /* -1 to compensate function */
+ lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
+ lua_call(L, 2, 1);
+ res = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ return res;
+ }
+ else /* a < b? */
+ return lua_compare(L, a, b, LUA_OPLT);
}
static void auxsort (lua_State *L, int l, int u) {
- while (l < u) { /* for tail recursion */
- int i, j;
- /* sort elements a[l], a[(l+u)/2] and a[u] */
- lua_rawgeti(L, 1, l);
- lua_rawgeti(L, 1, u);
- if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
- set2(L, l, u); /* swap a[l] - a[u] */
- else
- lua_pop(L, 2);
- if (u-l == 1) break; /* only 2 elements */
- i = (l+u)/2;
- lua_rawgeti(L, 1, i);
- lua_rawgeti(L, 1, l);
- if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */
- set2(L, i, l);
- else {
- lua_pop(L, 1); /* remove a[l] */
- lua_rawgeti(L, 1, u);
- if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */
- set2(L, i, u);
- else
- lua_pop(L, 2);
- }
- if (u-l == 2) break; /* only 3 elements */
- lua_rawgeti(L, 1, i); /* Pivot */
- lua_pushvalue(L, -1);
- lua_rawgeti(L, 1, u-1);
- set2(L, i, u-1);
- /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
- i = l; j = u-1;
- for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
- /* repeat ++i until a[i] >= P */
- while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
- if (i>=u) luaL_error(L, "invalid order function for sorting");
- lua_pop(L, 1); /* remove a[i] */
- }
- /* repeat --j until a[j] <= P */
- while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
- if (j<=l) luaL_error(L, "invalid order function for sorting");
- lua_pop(L, 1); /* remove a[j] */
- }
- if (j<i) {
- lua_pop(L, 3); /* pop pivot, a[i], a[j] */
- break;
- }
- set2(L, i, j);
- }
- lua_rawgeti(L, 1, u-1);
- lua_rawgeti(L, 1, i);
- set2(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */
- /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
- /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
- if (i-l < u-i) {
- j=l; i=i-1; l=i+2;
- }
- else {
- j=i+1; i=u; u=j-2;
- }
- auxsort(L, j, i); /* call recursively the smaller one */
- } /* repeat the routine for the larger one */
+ while (l < u) { /* for tail recursion */
+ int i, j;
+ /* sort elements a[l], a[(l+u)/2] and a[u] */
+ lua_rawgeti(L, 1, l);
+ lua_rawgeti(L, 1, u);
+ if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
+ set2(L, l, u); /* swap a[l] - a[u] */
+ else
+ lua_pop(L, 2);
+ if (u-l == 1) break; /* only 2 elements */
+ i = (l+u)/2;
+ lua_rawgeti(L, 1, i);
+ lua_rawgeti(L, 1, l);
+ if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */
+ set2(L, i, l);
+ else {
+ lua_pop(L, 1); /* remove a[l] */
+ lua_rawgeti(L, 1, u);
+ if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */
+ set2(L, i, u);
+ else
+ lua_pop(L, 2);
+ }
+ if (u-l == 2) break; /* only 3 elements */
+ lua_rawgeti(L, 1, i); /* Pivot */
+ lua_pushvalue(L, -1);
+ lua_rawgeti(L, 1, u-1);
+ set2(L, i, u-1);
+ /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
+ i = l; j = u-1;
+ for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
+ /* repeat ++i until a[i] >= P */
+ while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
+ if (i>=u) luaL_error(L, "invalid order function for sorting");
+ lua_pop(L, 1); /* remove a[i] */
+ }
+ /* repeat --j until a[j] <= P */
+ while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
+ if (j<=l) luaL_error(L, "invalid order function for sorting");
+ lua_pop(L, 1); /* remove a[j] */
+ }
+ if (j<i) {
+ lua_pop(L, 3); /* pop pivot, a[i], a[j] */
+ break;
+ }
+ set2(L, i, j);
+ }
+ lua_rawgeti(L, 1, u-1);
+ lua_rawgeti(L, 1, i);
+ set2(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */
+ /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
+ /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
+ if (i-l < u-i) {
+ j=l; i=i-1; l=i+2;
+ }
+ else {
+ j=i+1; i=u; u=j-2;
+ }
+ auxsort(L, j, i); /* call recursively the smaller one */
+ } /* repeat the routine for the larger one */
}
static int sort (lua_State *L) {
- int n = aux_getn(L, 1);
- luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */
- if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
- luaL_checktype(L, 2, LUA_TFUNCTION);
- lua_settop(L, 2); /* make sure there is two arguments */
- auxsort(L, 1, n);
- return 0;
+ int n = aux_getn(L, 1);
+ luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */
+ if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
+ luaL_checktype(L, 2, LUA_TFUNCTION);
+ lua_settop(L, 2); /* make sure there is two arguments */
+ auxsort(L, 1, n);
+ return 0;
}
/* }====================================================== */
static const luaL_Reg tab_funcs[] = {
- {"concat", tconcat},
+ {"concat", tconcat},
#if defined(LUA_COMPAT_MAXN)
- {"maxn", maxn},
+ {"maxn", maxn},
#endif
- {"insert", tinsert},
- {"pack", pack},
- {"unpack", unpack},
- {"remove", tremove},
- {"sort", sort},
- {NULL, NULL}
+ {"insert", tinsert},
+ {"pack", pack},
+ {"unpack", unpack},
+ {"remove", tremove},
+ {"sort", sort},
+ {NULL, NULL}
};
LUAMOD_API int luaopen_table (lua_State *L) {
- luaL_newlib(L, tab_funcs);
+ luaL_newlib(L, tab_funcs);
#if defined(LUA_COMPAT_UNPACK)
- /* _G.unpack = table.unpack */
- lua_getfield(L, -1, "unpack");
- lua_setglobal(L, "unpack");
+ /* _G.unpack = table.unpack */
+ lua_getfield(L, -1, "unpack");
+ lua_setglobal(L, "unpack");
#endif
- return 1;
+ return 1;
}
-
diff --git a/src/lib/lua/ltm.c b/src/lib/lua/ltm.c
index e70006dd7f6..4696b8e109b 100644
--- a/src/lib/lua/ltm.c
+++ b/src/lib/lua/ltm.c
@@ -22,26 +22,26 @@
static const char udatatypename[] = "userdata";
LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
- "no value",
- "nil", "boolean", udatatypename, "number",
- "string", "table", "function", udatatypename, "thread",
- "proto", "upval" /* these last two cases are used for tests only */
+ "no value",
+ "nil", "boolean", udatatypename, "number",
+ "string", "table", "function", udatatypename, "thread",
+ "proto", "upval" /* these last two cases are used for tests only */
};
void luaT_init (lua_State *L) {
- static const char *const luaT_eventname[] = { /* ORDER TM */
- "__index", "__newindex",
- "__gc", "__mode", "__len", "__eq",
- "__add", "__sub", "__mul", "__div", "__mod",
- "__pow", "__unm", "__lt", "__le",
- "__concat", "__call"
- };
- int i;
- for (i=0; i<TM_N; i++) {
- G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
- luaS_fix(G(L)->tmname[i]); /* never collect these names */
- }
+ static const char *const luaT_eventname[] = { /* ORDER TM */
+ "__index", "__newindex",
+ "__gc", "__mode", "__len", "__eq",
+ "__add", "__sub", "__mul", "__div", "__mod",
+ "__pow", "__unm", "__lt", "__le",
+ "__concat", "__call"
+ };
+ int i;
+ for (i=0; i<TM_N; i++) {
+ G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
+ luaS_fix(G(L)->tmname[i]); /* never collect these names */
+ }
}
@@ -50,28 +50,27 @@ void luaT_init (lua_State *L) {
** tag methods
*/
const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
- const TValue *tm = luaH_getstr(events, ename);
- lua_assert(event <= TM_EQ);
- if (ttisnil(tm)) { /* no tag method? */
- events->flags |= cast_byte(1u<<event); /* cache this fact */
- return NULL;
- }
- else return tm;
+ const TValue *tm = luaH_getstr(events, ename);
+ lua_assert(event <= TM_EQ);
+ if (ttisnil(tm)) { /* no tag method? */
+ events->flags |= cast_byte(1u<<event); /* cache this fact */
+ return NULL;
+ }
+ else return tm;
}
const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
- Table *mt;
- switch (ttypenv(o)) {
- case LUA_TTABLE:
- mt = hvalue(o)->metatable;
- break;
- case LUA_TUSERDATA:
- mt = uvalue(o)->metatable;
- break;
- default:
- mt = G(L)->mt[ttypenv(o)];
- }
- return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
+ Table *mt;
+ switch (ttypenv(o)) {
+ case LUA_TTABLE:
+ mt = hvalue(o)->metatable;
+ break;
+ case LUA_TUSERDATA:
+ mt = uvalue(o)->metatable;
+ break;
+ default:
+ mt = G(L)->mt[ttypenv(o)];
+ }
+ return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
}
-
diff --git a/src/lib/lua/ltm.h b/src/lib/lua/ltm.h
index 89bdc19a1e1..3d7a48f0a47 100644
--- a/src/lib/lua/ltm.h
+++ b/src/lib/lua/ltm.h
@@ -16,42 +16,42 @@
* grep "ORDER TM"
*/
typedef enum {
- TM_INDEX,
- TM_NEWINDEX,
- TM_GC,
- TM_MODE,
- TM_LEN,
- TM_EQ, /* last tag method with `fast' access */
- TM_ADD,
- TM_SUB,
- TM_MUL,
- TM_DIV,
- TM_MOD,
- TM_POW,
- TM_UNM,
- TM_LT,
- TM_LE,
- TM_CONCAT,
- TM_CALL,
- TM_N /* number of elements in the enum */
+ TM_INDEX,
+ TM_NEWINDEX,
+ TM_GC,
+ TM_MODE,
+ TM_LEN,
+ TM_EQ, /* last tag method with `fast' access */
+ TM_ADD,
+ TM_SUB,
+ TM_MUL,
+ TM_DIV,
+ TM_MOD,
+ TM_POW,
+ TM_UNM,
+ TM_LT,
+ TM_LE,
+ TM_CONCAT,
+ TM_CALL,
+ TM_N /* number of elements in the enum */
} TMS;
#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
- ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
+ ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
-#define fasttm(l,et,e) gfasttm(G(l), et, e)
+#define fasttm(l,et,e) gfasttm(G(l), et, e)
-#define ttypename(x) luaT_typenames_[(x) + 1]
-#define objtypename(x) ttypename(ttypenv(x))
+#define ttypename(x) luaT_typenames_[(x) + 1]
+#define objtypename(x) ttypename(ttypenv(x))
LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];
LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
- TMS event);
+ TMS event);
LUAI_FUNC void luaT_init (lua_State *L);
#endif
diff --git a/src/lib/lua/lua.c b/src/lib/lua/lua.c
index 6a007129202..7da82ea067c 100644
--- a/src/lib/lua/lua.c
+++ b/src/lib/lua/lua.c
@@ -19,20 +19,20 @@
#if !defined(LUA_PROMPT)
-#define LUA_PROMPT "> "
-#define LUA_PROMPT2 ">> "
+#define LUA_PROMPT "> "
+#define LUA_PROMPT2 ">> "
#endif
#if !defined(LUA_PROGNAME)
-#define LUA_PROGNAME "lua"
+#define LUA_PROGNAME "lua"
#endif
#if !defined(LUA_MAXINPUT)
-#define LUA_MAXINPUT 512
+#define LUA_MAXINPUT 512
#endif
#if !defined(LUA_INIT)
-#define LUA_INIT "LUA_INIT"
+#define LUA_INIT "LUA_INIT"
#endif
#define LUA_INITVERSION \
@@ -45,13 +45,13 @@
*/
#if defined(LUA_USE_ISATTY)
#include <unistd.h>
-#define lua_stdin_is_tty() isatty(0)
+#define lua_stdin_is_tty() isatty(0)
#elif defined(LUA_WIN)
#include <io.h>
#include <stdio.h>
-#define lua_stdin_is_tty() _isatty(_fileno(stdin))
+#define lua_stdin_is_tty() _isatty(_fileno(stdin))
#else
-#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
+#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
#endif
@@ -66,19 +66,19 @@
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
-#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
+#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
#define lua_saveline(L,idx) \
- if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \
- add_history(lua_tostring(L, idx)); /* add it to history */
-#define lua_freeline(L,b) ((void)L, free(b))
+ if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \
+ add_history(lua_tostring(L, idx)); /* add it to history */
+#define lua_freeline(L,b) ((void)L, free(b))
#elif !defined(lua_readline)
#define lua_readline(L,b,p) \
- ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
- fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
-#define lua_saveline(L,idx) { (void)L; (void)idx; }
-#define lua_freeline(L,b) { (void)L; (void)b; }
+ ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
+ fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
+#define lua_saveline(L,idx) { (void)L; (void)idx; }
+#define lua_freeline(L,b) { (void)L; (void)b; }
#endif
@@ -92,406 +92,405 @@ static const char *progname = LUA_PROGNAME;
static void lstop (lua_State *L, lua_Debug *ar) {
- (void)ar; /* unused arg. */
- lua_sethook(L, NULL, 0, 0);
- luaL_error(L, "interrupted!");
+ (void)ar; /* unused arg. */
+ lua_sethook(L, NULL, 0, 0);
+ luaL_error(L, "interrupted!");
}
static void laction (int i) {
- signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
+ signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
terminate process (default action) */
- lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
+ lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
}
static void print_usage (const char *badoption) {
- luai_writestringerror("%s: ", progname);
- if (badoption[1] == 'e' || badoption[1] == 'l')
- luai_writestringerror("'%s' needs argument\n", badoption);
- else
- luai_writestringerror("unrecognized option '%s'\n", badoption);
- luai_writestringerror(
- "usage: %s [options] [script [args]]\n"
- "Available options are:\n"
- " -e stat execute string " LUA_QL("stat") "\n"
- " -i enter interactive mode after executing " LUA_QL("script") "\n"
- " -l name require library " LUA_QL("name") "\n"
- " -v show version information\n"
- " -E ignore environment variables\n"
- " -- stop handling options\n"
- " - stop handling options and execute stdin\n"
- ,
- progname);
+ luai_writestringerror("%s: ", progname);
+ if (badoption[1] == 'e' || badoption[1] == 'l')
+ luai_writestringerror("'%s' needs argument\n", badoption);
+ else
+ luai_writestringerror("unrecognized option '%s'\n", badoption);
+ luai_writestringerror(
+ "usage: %s [options] [script [args]]\n"
+ "Available options are:\n"
+ " -e stat execute string " LUA_QL("stat") "\n"
+ " -i enter interactive mode after executing " LUA_QL("script") "\n"
+ " -l name require library " LUA_QL("name") "\n"
+ " -v show version information\n"
+ " -E ignore environment variables\n"
+ " -- stop handling options\n"
+ " - stop handling options and execute stdin\n"
+ ,
+ progname);
}
static void l_message (const char *pname, const char *msg) {
- if (pname) luai_writestringerror("%s: ", pname);
- luai_writestringerror("%s\n", msg);
+ if (pname) luai_writestringerror("%s: ", pname);
+ luai_writestringerror("%s\n", msg);
}
static int report (lua_State *L, int status) {
- if (status != LUA_OK && !lua_isnil(L, -1)) {
- const char *msg = lua_tostring(L, -1);
- if (msg == NULL) msg = "(error object is not a string)";
- l_message(progname, msg);
- lua_pop(L, 1);
- /* force a complete garbage collection in case of errors */
- lua_gc(L, LUA_GCCOLLECT, 0);
- }
- return status;
+ if (status != LUA_OK && !lua_isnil(L, -1)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(progname, msg);
+ lua_pop(L, 1);
+ /* force a complete garbage collection in case of errors */
+ lua_gc(L, LUA_GCCOLLECT, 0);
+ }
+ return status;
}
/* the next function is called unprotected, so it must avoid errors */
static void finalreport (lua_State *L, int status) {
- if (status != LUA_OK) {
- const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1)
- : NULL;
- if (msg == NULL) msg = "(error object is not a string)";
- l_message(progname, msg);
- lua_pop(L, 1);
- }
+ if (status != LUA_OK) {
+ const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1)
+ : NULL;
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(progname, msg);
+ lua_pop(L, 1);
+ }
}
static int traceback (lua_State *L) {
- const char *msg = lua_tostring(L, 1);
- if (msg)
- luaL_traceback(L, L, msg, 1);
- else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */
- if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */
- lua_pushliteral(L, "(no error message)");
- }
- return 1;
+ const char *msg = lua_tostring(L, 1);
+ if (msg)
+ luaL_traceback(L, L, msg, 1);
+ else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */
+ if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */
+ lua_pushliteral(L, "(no error message)");
+ }
+ return 1;
}
static int docall (lua_State *L, int narg, int nres) {
- int status;
- int base = lua_gettop(L) - narg; /* function index */
- lua_pushcfunction(L, traceback); /* push traceback function */
- lua_insert(L, base); /* put it under chunk and args */
- globalL = L; /* to be available to 'laction' */
- signal(SIGINT, laction);
- status = lua_pcall(L, narg, nres, base);
- signal(SIGINT, SIG_DFL);
- lua_remove(L, base); /* remove traceback function */
- return status;
+ int status;
+ int base = lua_gettop(L) - narg; /* function index */
+ lua_pushcfunction(L, traceback); /* push traceback function */
+ lua_insert(L, base); /* put it under chunk and args */
+ globalL = L; /* to be available to 'laction' */
+ signal(SIGINT, laction);
+ status = lua_pcall(L, narg, nres, base);
+ signal(SIGINT, SIG_DFL);
+ lua_remove(L, base); /* remove traceback function */
+ return status;
}
static void print_version (void) {
- luai_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
- luai_writeline();
+ luai_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
+ luai_writeline();
}
static int getargs (lua_State *L, char **argv, int n) {
- int narg;
- int i;
- int argc = 0;
- while (argv[argc]) argc++; /* count total number of arguments */
- narg = argc - (n + 1); /* number of arguments to the script */
- luaL_checkstack(L, narg + 3, "too many arguments to script");
- for (i=n+1; i < argc; i++)
- lua_pushstring(L, argv[i]);
- lua_createtable(L, narg, n + 1);
- for (i=0; i < argc; i++) {
- lua_pushstring(L, argv[i]);
- lua_rawseti(L, -2, i - n);
- }
- return narg;
+ int narg;
+ int i;
+ int argc = 0;
+ while (argv[argc]) argc++; /* count total number of arguments */
+ narg = argc - (n + 1); /* number of arguments to the script */
+ luaL_checkstack(L, narg + 3, "too many arguments to script");
+ for (i=n+1; i < argc; i++)
+ lua_pushstring(L, argv[i]);
+ lua_createtable(L, narg, n + 1);
+ for (i=0; i < argc; i++) {
+ lua_pushstring(L, argv[i]);
+ lua_rawseti(L, -2, i - n);
+ }
+ return narg;
}
static int dofile (lua_State *L, const char *name) {
- int status = luaL_loadfile(L, name);
- if (status == LUA_OK) status = docall(L, 0, 0);
- return report(L, status);
+ int status = luaL_loadfile(L, name);
+ if (status == LUA_OK) status = docall(L, 0, 0);
+ return report(L, status);
}
static int dostring (lua_State *L, const char *s, const char *name) {
- int status = luaL_loadbuffer(L, s, strlen(s), name);
- if (status == LUA_OK) status = docall(L, 0, 0);
- return report(L, status);
+ int status = luaL_loadbuffer(L, s, strlen(s), name);
+ if (status == LUA_OK) status = docall(L, 0, 0);
+ return report(L, status);
}
static int dolibrary (lua_State *L, const char *name) {
- int status;
- lua_getglobal(L, "require");
- lua_pushstring(L, name);
- status = docall(L, 1, 1); /* call 'require(name)' */
- if (status == LUA_OK)
- lua_setglobal(L, name); /* global[name] = require return */
- return report(L, status);
+ int status;
+ lua_getglobal(L, "require");
+ lua_pushstring(L, name);
+ status = docall(L, 1, 1); /* call 'require(name)' */
+ if (status == LUA_OK)
+ lua_setglobal(L, name); /* global[name] = require return */
+ return report(L, status);
}
static const char *get_prompt (lua_State *L, int firstline) {
- const char *p;
- lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
- p = lua_tostring(L, -1);
- if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
- return p;
+ const char *p;
+ lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
+ p = lua_tostring(L, -1);
+ if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
+ return p;
}
/* mark in error messages for incomplete statements */
-#define EOFMARK "<eof>"
-#define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
+#define EOFMARK "<eof>"
+#define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
static int incomplete (lua_State *L, int status) {
- if (status == LUA_ERRSYNTAX) {
- size_t lmsg;
- const char *msg = lua_tolstring(L, -1, &lmsg);
- if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
- lua_pop(L, 1);
- return 1;
- }
- }
- return 0; /* else... */
+ if (status == LUA_ERRSYNTAX) {
+ size_t lmsg;
+ const char *msg = lua_tolstring(L, -1, &lmsg);
+ if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
+ lua_pop(L, 1);
+ return 1;
+ }
+ }
+ return 0; /* else... */
}
static int pushline (lua_State *L, int firstline) {
- char buffer[LUA_MAXINPUT];
- char *b = buffer;
- size_t l;
- const char *prmt = get_prompt(L, firstline);
- int readstatus = lua_readline(L, b, prmt);
- lua_pop(L, 1); /* remove result from 'get_prompt' */
- if (readstatus == 0)
- return 0; /* no input */
- l = strlen(b);
- if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
- b[l-1] = '\0'; /* remove it */
- if (firstline && b[0] == '=') /* first line starts with `=' ? */
- lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
- else
- lua_pushstring(L, b);
- lua_freeline(L, b);
- return 1;
+ char buffer[LUA_MAXINPUT];
+ char *b = buffer;
+ size_t l;
+ const char *prmt = get_prompt(L, firstline);
+ int readstatus = lua_readline(L, b, prmt);
+ lua_pop(L, 1); /* remove result from 'get_prompt' */
+ if (readstatus == 0)
+ return 0; /* no input */
+ l = strlen(b);
+ if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
+ b[l-1] = '\0'; /* remove it */
+ if (firstline && b[0] == '=') /* first line starts with `=' ? */
+ lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
+ else
+ lua_pushstring(L, b);
+ lua_freeline(L, b);
+ return 1;
}
static int loadline (lua_State *L) {
- int status;
- lua_settop(L, 0);
- if (!pushline(L, 1))
- return -1; /* no input */
- for (;;) { /* repeat until gets a complete line */
- size_t l;
- const char *line = lua_tolstring(L, 1, &l);
- status = luaL_loadbuffer(L, line, l, "=stdin");
- if (!incomplete(L, status)) break; /* cannot try to add lines? */
- if (!pushline(L, 0)) /* no more input? */
- return -1;
- lua_pushliteral(L, "\n"); /* add a new line... */
- lua_insert(L, -2); /* ...between the two lines */
- lua_concat(L, 3); /* join them */
- }
- lua_saveline(L, 1);
- lua_remove(L, 1); /* remove line */
- return status;
+ int status;
+ lua_settop(L, 0);
+ if (!pushline(L, 1))
+ return -1; /* no input */
+ for (;;) { /* repeat until gets a complete line */
+ size_t l;
+ const char *line = lua_tolstring(L, 1, &l);
+ status = luaL_loadbuffer(L, line, l, "=stdin");
+ if (!incomplete(L, status)) break; /* cannot try to add lines? */
+ if (!pushline(L, 0)) /* no more input? */
+ return -1;
+ lua_pushliteral(L, "\n"); /* add a new line... */
+ lua_insert(L, -2); /* ...between the two lines */
+ lua_concat(L, 3); /* join them */
+ }
+ lua_saveline(L, 1);
+ lua_remove(L, 1); /* remove line */
+ return status;
}
static void dotty (lua_State *L) {
- int status;
- const char *oldprogname = progname;
- progname = NULL;
- while ((status = loadline(L)) != -1) {
- if (status == LUA_OK) status = docall(L, 0, LUA_MULTRET);
- report(L, status);
- if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
- luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
- lua_getglobal(L, "print");
- lua_insert(L, 1);
- if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
- l_message(progname, lua_pushfstring(L,
- "error calling " LUA_QL("print") " (%s)",
- lua_tostring(L, -1)));
- }
- }
- lua_settop(L, 0); /* clear stack */
- luai_writeline();
- progname = oldprogname;
+ int status;
+ const char *oldprogname = progname;
+ progname = NULL;
+ while ((status = loadline(L)) != -1) {
+ if (status == LUA_OK) status = docall(L, 0, LUA_MULTRET);
+ report(L, status);
+ if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
+ luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
+ lua_getglobal(L, "print");
+ lua_insert(L, 1);
+ if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
+ l_message(progname, lua_pushfstring(L,
+ "error calling " LUA_QL("print") " (%s)",
+ lua_tostring(L, -1)));
+ }
+ }
+ lua_settop(L, 0); /* clear stack */
+ luai_writeline();
+ progname = oldprogname;
}
static int handle_script (lua_State *L, char **argv, int n) {
- int status;
- const char *fname;
- int narg = getargs(L, argv, n); /* collect arguments */
- lua_setglobal(L, "arg");
- fname = argv[n];
- if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
- fname = NULL; /* stdin */
- status = luaL_loadfile(L, fname);
- lua_insert(L, -(narg+1));
- if (status == LUA_OK)
- status = docall(L, narg, LUA_MULTRET);
- else
- lua_pop(L, narg);
- return report(L, status);
+ int status;
+ const char *fname;
+ int narg = getargs(L, argv, n); /* collect arguments */
+ lua_setglobal(L, "arg");
+ fname = argv[n];
+ if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
+ fname = NULL; /* stdin */
+ status = luaL_loadfile(L, fname);
+ lua_insert(L, -(narg+1));
+ if (status == LUA_OK)
+ status = docall(L, narg, LUA_MULTRET);
+ else
+ lua_pop(L, narg);
+ return report(L, status);
}
/* check that argument has no extra characters at the end */
-#define noextrachars(x) {if ((x)[2] != '\0') return -1;}
+#define noextrachars(x) {if ((x)[2] != '\0') return -1;}
/* indices of various argument indicators in array args */
-#define has_i 0 /* -i */
-#define has_v 1 /* -v */
-#define has_e 2 /* -e */
-#define has_E 3 /* -E */
+#define has_i 0 /* -i */
+#define has_v 1 /* -v */
+#define has_e 2 /* -e */
+#define has_E 3 /* -E */
-#define num_has 4 /* number of 'has_*' */
+#define num_has 4 /* number of 'has_*' */
static int collectargs (char **argv, int *args) {
- int i;
- for (i = 1; argv[i] != NULL; i++) {
- if (argv[i][0] != '-') /* not an option? */
- return i;
- switch (argv[i][1]) { /* option */
- case '-':
- noextrachars(argv[i]);
- return (argv[i+1] != NULL ? i+1 : 0);
- case '\0':
- return i;
- case 'E':
- args[has_E] = 1;
- break;
- case 'i':
- noextrachars(argv[i]);
- args[has_i] = 1; /* go through */
- case 'v':
- noextrachars(argv[i]);
- args[has_v] = 1;
- break;
- case 'e':
- args[has_e] = 1; /* go through */
- case 'l': /* both options need an argument */
- if (argv[i][2] == '\0') { /* no concatenated argument? */
- i++; /* try next 'argv' */
- if (argv[i] == NULL || argv[i][0] == '-')
- return -(i - 1); /* no next argument or it is another option */
- }
- break;
- default: /* invalid option; return its index... */
- return -i; /* ...as a negative value */
- }
- }
- return 0;
+ int i;
+ for (i = 1; argv[i] != NULL; i++) {
+ if (argv[i][0] != '-') /* not an option? */
+ return i;
+ switch (argv[i][1]) { /* option */
+ case '-':
+ noextrachars(argv[i]);
+ return (argv[i+1] != NULL ? i+1 : 0);
+ case '\0':
+ return i;
+ case 'E':
+ args[has_E] = 1;
+ break;
+ case 'i':
+ noextrachars(argv[i]);
+ args[has_i] = 1; /* go through */
+ case 'v':
+ noextrachars(argv[i]);
+ args[has_v] = 1;
+ break;
+ case 'e':
+ args[has_e] = 1; /* go through */
+ case 'l': /* both options need an argument */
+ if (argv[i][2] == '\0') { /* no concatenated argument? */
+ i++; /* try next 'argv' */
+ if (argv[i] == NULL || argv[i][0] == '-')
+ return -(i - 1); /* no next argument or it is another option */
+ }
+ break;
+ default: /* invalid option; return its index... */
+ return -i; /* ...as a negative value */
+ }
+ }
+ return 0;
}
static int runargs (lua_State *L, char **argv, int n) {
- int i;
- for (i = 1; i < n; i++) {
- lua_assert(argv[i][0] == '-');
- switch (argv[i][1]) { /* option */
- case 'e': {
- const char *chunk = argv[i] + 2;
- if (*chunk == '\0') chunk = argv[++i];
- lua_assert(chunk != NULL);
- if (dostring(L, chunk, "=(command line)") != LUA_OK)
- return 0;
- break;
- }
- case 'l': {
- const char *filename = argv[i] + 2;
- if (*filename == '\0') filename = argv[++i];
- lua_assert(filename != NULL);
- if (dolibrary(L, filename) != LUA_OK)
- return 0; /* stop if file fails */
- break;
- }
- default: break;
- }
- }
- return 1;
+ int i;
+ for (i = 1; i < n; i++) {
+ lua_assert(argv[i][0] == '-');
+ switch (argv[i][1]) { /* option */
+ case 'e': {
+ const char *chunk = argv[i] + 2;
+ if (*chunk == '\0') chunk = argv[++i];
+ lua_assert(chunk != NULL);
+ if (dostring(L, chunk, "=(command line)") != LUA_OK)
+ return 0;
+ break;
+ }
+ case 'l': {
+ const char *filename = argv[i] + 2;
+ if (*filename == '\0') filename = argv[++i];
+ lua_assert(filename != NULL);
+ if (dolibrary(L, filename) != LUA_OK)
+ return 0; /* stop if file fails */
+ break;
+ }
+ default: break;
+ }
+ }
+ return 1;
}
static int handle_luainit (lua_State *L) {
- const char *name = "=" LUA_INITVERSION;
- const char *init = getenv(name + 1);
- if (init == NULL) {
- name = "=" LUA_INIT;
- init = getenv(name + 1); /* try alternative name */
- }
- if (init == NULL) return LUA_OK;
- else if (init[0] == '@')
- return dofile(L, init+1);
- else
- return dostring(L, init, name);
+ const char *name = "=" LUA_INITVERSION;
+ const char *init = getenv(name + 1);
+ if (init == NULL) {
+ name = "=" LUA_INIT;
+ init = getenv(name + 1); /* try alternative name */
+ }
+ if (init == NULL) return LUA_OK;
+ else if (init[0] == '@')
+ return dofile(L, init+1);
+ else
+ return dostring(L, init, name);
}
static int pmain (lua_State *L) {
- int argc = (int)lua_tointeger(L, 1);
- char **argv = (char **)lua_touserdata(L, 2);
- int script;
- int args[num_has];
- args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
- if (argv[0] && argv[0][0]) progname = argv[0];
- script = collectargs(argv, args);
- if (script < 0) { /* invalid arg? */
- print_usage(argv[-script]);
- return 0;
- }
- if (args[has_v]) print_version();
- if (args[has_E]) { /* option '-E'? */
- lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
- lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
- }
- /* open standard libraries */
- luaL_checkversion(L);
- lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
- luaL_openlibs(L); /* open libraries */
- lua_gc(L, LUA_GCRESTART, 0);
- if (!args[has_E] && handle_luainit(L) != LUA_OK)
- return 0; /* error running LUA_INIT */
- /* execute arguments -e and -l */
- if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
- /* execute main script (if there is one) */
- if (script && handle_script(L, argv, script) != LUA_OK) return 0;
- if (args[has_i]) /* -i option? */
- dotty(L);
- else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */
- if (lua_stdin_is_tty()) {
- print_version();
- dotty(L);
- }
- else dofile(L, NULL); /* executes stdin as a file */
- }
- lua_pushboolean(L, 1); /* signal no errors */
- return 1;
+ int argc = (int)lua_tointeger(L, 1);
+ char **argv = (char **)lua_touserdata(L, 2);
+ int script;
+ int args[num_has];
+ args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
+ if (argv[0] && argv[0][0]) progname = argv[0];
+ script = collectargs(argv, args);
+ if (script < 0) { /* invalid arg? */
+ print_usage(argv[-script]);
+ return 0;
+ }
+ if (args[has_v]) print_version();
+ if (args[has_E]) { /* option '-E'? */
+ lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
+ lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ }
+ /* open standard libraries */
+ luaL_checkversion(L);
+ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
+ luaL_openlibs(L); /* open libraries */
+ lua_gc(L, LUA_GCRESTART, 0);
+ if (!args[has_E] && handle_luainit(L) != LUA_OK)
+ return 0; /* error running LUA_INIT */
+ /* execute arguments -e and -l */
+ if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
+ /* execute main script (if there is one) */
+ if (script && handle_script(L, argv, script) != LUA_OK) return 0;
+ if (args[has_i]) /* -i option? */
+ dotty(L);
+ else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */
+ if (lua_stdin_is_tty()) {
+ print_version();
+ dotty(L);
+ }
+ else dofile(L, NULL); /* executes stdin as a file */
+ }
+ lua_pushboolean(L, 1); /* signal no errors */
+ return 1;
}
int main (int argc, char **argv) {
- int status, result;
- lua_State *L = luaL_newstate(); /* create state */
- if (L == NULL) {
- l_message(argv[0], "cannot create state: not enough memory");
- return EXIT_FAILURE;
- }
- /* call 'pmain' in protected mode */
- lua_pushcfunction(L, &pmain);
- lua_pushinteger(L, argc); /* 1st argument */
- lua_pushlightuserdata(L, argv); /* 2nd argument */
- status = lua_pcall(L, 2, 1, 0);
- result = lua_toboolean(L, -1); /* get result */
- finalreport(L, status);
- lua_close(L);
- return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
+ int status, result;
+ lua_State *L = luaL_newstate(); /* create state */
+ if (L == NULL) {
+ l_message(argv[0], "cannot create state: not enough memory");
+ return EXIT_FAILURE;
+ }
+ /* call 'pmain' in protected mode */
+ lua_pushcfunction(L, &pmain);
+ lua_pushinteger(L, argc); /* 1st argument */
+ lua_pushlightuserdata(L, argv); /* 2nd argument */
+ status = lua_pcall(L, 2, 1, 0);
+ result = lua_toboolean(L, -1); /* get result */
+ finalreport(L, status);
+ lua_close(L);
+ return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
-
diff --git a/src/lib/lua/lua.h b/src/lib/lua/lua.h
index eb0482b8f47..4ad0da4ae5b 100644
--- a/src/lib/lua/lua.h
+++ b/src/lib/lua/lua.h
@@ -16,39 +16,39 @@
#include "luaconf.h"
-#define LUA_VERSION_MAJOR "5"
-#define LUA_VERSION_MINOR "2"
-#define LUA_VERSION_NUM 502
-#define LUA_VERSION_RELEASE "2"
+#define LUA_VERSION_MAJOR "5"
+#define LUA_VERSION_MINOR "2"
+#define LUA_VERSION_NUM 502
+#define LUA_VERSION_RELEASE "2"
-#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
-#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
-#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2013 Lua.org, PUC-Rio"
-#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
+#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
+#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
+#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2013 Lua.org, PUC-Rio"
+#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
-#define LUA_SIGNATURE "\033Lua"
+#define LUA_SIGNATURE "\033Lua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
-#define LUA_MULTRET (-1)
+#define LUA_MULTRET (-1)
/*
** pseudo-indices
*/
-#define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
-#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
+#define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
+#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
-#define LUA_OK 0
-#define LUA_YIELD 1
-#define LUA_ERRRUN 2
-#define LUA_ERRSYNTAX 3
-#define LUA_ERRMEM 4
-#define LUA_ERRGCMM 5
-#define LUA_ERRERR 6
+#define LUA_OK 0
+#define LUA_YIELD 1
+#define LUA_ERRRUN 2
+#define LUA_ERRSYNTAX 3
+#define LUA_ERRMEM 4
+#define LUA_ERRGCMM 5
+#define LUA_ERRERR 6
typedef struct lua_State lua_State;
@@ -73,30 +73,30 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** basic types
*/
-#define LUA_TNONE (-1)
+#define LUA_TNONE (-1)
-#define LUA_TNIL 0
-#define LUA_TBOOLEAN 1
-#define LUA_TLIGHTUSERDATA 2
-#define LUA_TNUMBER 3
-#define LUA_TSTRING 4
-#define LUA_TTABLE 5
-#define LUA_TFUNCTION 6
-#define LUA_TUSERDATA 7
-#define LUA_TTHREAD 8
+#define LUA_TNIL 0
+#define LUA_TBOOLEAN 1
+#define LUA_TLIGHTUSERDATA 2
+#define LUA_TNUMBER 3
+#define LUA_TSTRING 4
+#define LUA_TTABLE 5
+#define LUA_TFUNCTION 6
+#define LUA_TUSERDATA 7
+#define LUA_TTHREAD 8
-#define LUA_NUMTAGS 9
+#define LUA_NUMTAGS 9
/* minimum Lua stack available to a C function */
-#define LUA_MINSTACK 20
+#define LUA_MINSTACK 20
/* predefined values in the registry */
-#define LUA_RIDX_MAINTHREAD 1
-#define LUA_RIDX_GLOBALS 2
-#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
+#define LUA_RIDX_MAINTHREAD 1
+#define LUA_RIDX_GLOBALS 2
+#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
@@ -172,7 +172,7 @@ LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
-LUA_API void *(lua_touserdata) (lua_State *L, int idx);
+LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
@@ -181,19 +181,19 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx);
** Comparison and arithmetic functions
*/
-#define LUA_OPADD 0 /* ORDER TM */
-#define LUA_OPSUB 1
-#define LUA_OPMUL 2
-#define LUA_OPDIV 3
-#define LUA_OPMOD 4
-#define LUA_OPPOW 5
-#define LUA_OPUNM 6
+#define LUA_OPADD 0 /* ORDER TM */
+#define LUA_OPSUB 1
+#define LUA_OPMUL 2
+#define LUA_OPDIV 3
+#define LUA_OPMOD 4
+#define LUA_OPPOW 5
+#define LUA_OPUNM 6
LUA_API void (lua_arith) (lua_State *L, int op);
-#define LUA_OPEQ 0
-#define LUA_OPLT 1
-#define LUA_OPLE 2
+#define LUA_OPEQ 0
+#define LUA_OPLT 1
+#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
@@ -209,7 +209,7 @@ LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
- va_list argp);
+ va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
@@ -249,18 +249,18 @@ LUA_API void (lua_setuservalue) (lua_State *L, int idx);
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
- lua_CFunction k);
-#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
+ lua_CFunction k);
+#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_getctx) (lua_State *L, int *ctx);
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
- int ctx, lua_CFunction k);
-#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
+ int ctx, lua_CFunction k);
+#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
- const char *chunkname,
- const char *mode);
+ const char *chunkname,
+ const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
@@ -269,8 +269,8 @@ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
- lua_CFunction k);
-#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
+ lua_CFunction k);
+#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
LUA_API int (lua_status) (lua_State *L);
@@ -278,18 +278,18 @@ LUA_API int (lua_status) (lua_State *L);
** garbage-collection function and options
*/
-#define LUA_GCSTOP 0
-#define LUA_GCRESTART 1
-#define LUA_GCCOLLECT 2
-#define LUA_GCCOUNT 3
-#define LUA_GCCOUNTB 4
-#define LUA_GCSTEP 5
-#define LUA_GCSETPAUSE 6
-#define LUA_GCSETSTEPMUL 7
-#define LUA_GCSETMAJORINC 8
-#define LUA_GCISRUNNING 9
-#define LUA_GCGEN 10
-#define LUA_GCINC 11
+#define LUA_GCSTOP 0
+#define LUA_GCRESTART 1
+#define LUA_GCCOLLECT 2
+#define LUA_GCCOUNT 3
+#define LUA_GCCOUNTB 4
+#define LUA_GCSTEP 5
+#define LUA_GCSETPAUSE 6
+#define LUA_GCSETSTEPMUL 7
+#define LUA_GCSETMAJORINC 8
+#define LUA_GCISRUNNING 9
+#define LUA_GCGEN 10
+#define LUA_GCINC 11
LUA_API int (lua_gc) (lua_State *L, int what, int data);
@@ -316,34 +316,34 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
** ===============================================================
*/
-#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
-#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
-#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
+#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
+#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
+#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
-#define lua_pop(L,n) lua_settop(L, -(n)-1)
+#define lua_pop(L,n) lua_settop(L, -(n)-1)
-#define lua_newtable(L) lua_createtable(L, 0, 0)
+#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
-#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
+#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
-#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
-#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
-#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
-#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
-#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
-#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
-#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
-#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
+#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
+#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
+#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
+#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
+#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
+#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
+#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
+#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
-#define lua_pushliteral(L, s) \
+#define lua_pushliteral(L, s) \
lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
#define lua_pushglobaltable(L) \
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
-#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
+#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
@@ -357,20 +357,20 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
/*
** Event codes
*/
-#define LUA_HOOKCALL 0
-#define LUA_HOOKRET 1
-#define LUA_HOOKLINE 2
-#define LUA_HOOKCOUNT 3
+#define LUA_HOOKCALL 0
+#define LUA_HOOKRET 1
+#define LUA_HOOKLINE 2
+#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
-#define LUA_MASKCALL (1 << LUA_HOOKCALL)
-#define LUA_MASKRET (1 << LUA_HOOKRET)
-#define LUA_MASKLINE (1 << LUA_HOOKLINE)
-#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
+#define LUA_MASKCALL (1 << LUA_HOOKCALL)
+#define LUA_MASKRET (1 << LUA_HOOKRET)
+#define LUA_MASKLINE (1 << LUA_HOOKLINE)
+#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
@@ -388,7 +388,7 @@ LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
- int fidx2, int n2);
+ int fidx2, int n2);
LUA_API int (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
@@ -397,21 +397,21 @@ LUA_API int (lua_gethookcount) (lua_State *L);
struct lua_Debug {
- int event;
- const char *name; /* (n) */
- const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
- const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
- const char *source; /* (S) */
- int currentline; /* (l) */
- int linedefined; /* (S) */
- int lastlinedefined; /* (S) */
- unsigned char nups; /* (u) number of upvalues */
- unsigned char nparams;/* (u) number of parameters */
- char isvararg; /* (u) */
- char istailcall; /* (t) */
- char short_src[LUA_IDSIZE]; /* (S) */
- /* private part */
- struct CallInfo *i_ci; /* active function */
+ int event;
+ const char *name; /* (n) */
+ const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
+ const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
+ const char *source; /* (S) */
+ int currentline; /* (l) */
+ int linedefined; /* (S) */
+ int lastlinedefined; /* (S) */
+ unsigned char nups; /* (u) number of upvalues */
+ unsigned char nparams;/* (u) number of parameters */
+ char isvararg; /* (u) */
+ char istailcall; /* (t) */
+ char short_src[LUA_IDSIZE]; /* (S) */
+ /* private part */
+ struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
diff --git a/src/lib/lua/luac.c b/src/lib/lua/luac.c
index 5081836d4cb..67f8b7c2c01 100644
--- a/src/lib/lua/luac.c
+++ b/src/lib/lua/luac.c
@@ -20,186 +20,186 @@
#include "lundump.h"
static void PrintFunction(const Proto* f, int full);
-#define luaU_print PrintFunction
+#define luaU_print PrintFunction
-#define PROGNAME "luac" /* default program name */
-#define OUTPUT PROGNAME ".out" /* default output file */
+#define PROGNAME "luac" /* default program name */
+#define OUTPUT PROGNAME ".out" /* default output file */
-static int listing=0; /* list bytecodes? */
-static int dumping=1; /* dump bytecodes? */
-static int stripping=0; /* strip debug information? */
-static char Output[]={ OUTPUT }; /* default output file name */
-static const char* output=Output; /* actual output file name */
-static const char* progname=PROGNAME; /* actual program name */
+static int listing=0; /* list bytecodes? */
+static int dumping=1; /* dump bytecodes? */
+static int stripping=0; /* strip debug information? */
+static char Output[]={ OUTPUT }; /* default output file name */
+static const char* output=Output; /* actual output file name */
+static const char* progname=PROGNAME; /* actual program name */
static void fatal(const char* message)
{
- fprintf(stderr,"%s: %s\n",progname,message);
- exit(EXIT_FAILURE);
+ fprintf(stderr,"%s: %s\n",progname,message);
+ exit(EXIT_FAILURE);
}
static void cannot(const char* what)
{
- fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
- exit(EXIT_FAILURE);
+ fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
+ exit(EXIT_FAILURE);
}
static void usage(const char* message)
{
- if (*message=='-')
- fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
- else
- fprintf(stderr,"%s: %s\n",progname,message);
- fprintf(stderr,
- "usage: %s [options] [filenames]\n"
- "Available options are:\n"
- " -l list (use -l -l for full listing)\n"
- " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
- " -p parse only\n"
- " -s strip debug information\n"
- " -v show version information\n"
- " -- stop handling options\n"
- " - stop handling options and process stdin\n"
- ,progname,Output);
- exit(EXIT_FAILURE);
+ if (*message=='-')
+ fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
+ else
+ fprintf(stderr,"%s: %s\n",progname,message);
+ fprintf(stderr,
+ "usage: %s [options] [filenames]\n"
+ "Available options are:\n"
+ " -l list (use -l -l for full listing)\n"
+ " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
+ " -p parse only\n"
+ " -s strip debug information\n"
+ " -v show version information\n"
+ " -- stop handling options\n"
+ " - stop handling options and process stdin\n"
+ ,progname,Output);
+ exit(EXIT_FAILURE);
}
-#define IS(s) (strcmp(argv[i],s)==0)
+#define IS(s) (strcmp(argv[i],s)==0)
static int doargs(int argc, char* argv[])
{
- int i;
- int version=0;
- if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
- for (i=1; i<argc; i++)
- {
- if (*argv[i]!='-') /* end of options; keep it */
- break;
- else if (IS("--")) /* end of options; skip it */
- {
- ++i;
- if (version) ++version;
- break;
- }
- else if (IS("-")) /* end of options; use stdin */
- break;
- else if (IS("-l")) /* list */
- ++listing;
- else if (IS("-o")) /* output file */
- {
- output=argv[++i];
- if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))
- usage(LUA_QL("-o") " needs argument");
- if (IS("-")) output=NULL;
- }
- else if (IS("-p")) /* parse only */
- dumping=0;
- else if (IS("-s")) /* strip debug information */
- stripping=1;
- else if (IS("-v")) /* show version */
- ++version;
- else /* unknown option */
- usage(argv[i]);
- }
- if (i==argc && (listing || !dumping))
- {
- dumping=0;
- argv[--i]=Output;
- }
- if (version)
- {
- printf("%s\n",LUA_COPYRIGHT);
- if (version==argc-1) exit(EXIT_SUCCESS);
- }
- return i;
+ int i;
+ int version=0;
+ if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
+ for (i=1; i<argc; i++)
+ {
+ if (*argv[i]!='-') /* end of options; keep it */
+ break;
+ else if (IS("--")) /* end of options; skip it */
+ {
+ ++i;
+ if (version) ++version;
+ break;
+ }
+ else if (IS("-")) /* end of options; use stdin */
+ break;
+ else if (IS("-l")) /* list */
+ ++listing;
+ else if (IS("-o")) /* output file */
+ {
+ output=argv[++i];
+ if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))
+ usage(LUA_QL("-o") " needs argument");
+ if (IS("-")) output=NULL;
+ }
+ else if (IS("-p")) /* parse only */
+ dumping=0;
+ else if (IS("-s")) /* strip debug information */
+ stripping=1;
+ else if (IS("-v")) /* show version */
+ ++version;
+ else /* unknown option */
+ usage(argv[i]);
+ }
+ if (i==argc && (listing || !dumping))
+ {
+ dumping=0;
+ argv[--i]=Output;
+ }
+ if (version)
+ {
+ printf("%s\n",LUA_COPYRIGHT);
+ if (version==argc-1) exit(EXIT_SUCCESS);
+ }
+ return i;
}
#define FUNCTION "(function()end)();"
static const char* reader(lua_State *L, void *ud, size_t *size)
{
- UNUSED(L);
- if ((*(int*)ud)--)
- {
- *size=sizeof(FUNCTION)-1;
- return FUNCTION;
- }
- else
- {
- *size=0;
- return NULL;
- }
+ UNUSED(L);
+ if ((*(int*)ud)--)
+ {
+ *size=sizeof(FUNCTION)-1;
+ return FUNCTION;
+ }
+ else
+ {
+ *size=0;
+ return NULL;
+ }
}
#define toproto(L,i) getproto(L->top+(i))
static const Proto* combine(lua_State* L, int n)
{
- if (n==1)
- return toproto(L,-1);
- else
- {
- Proto* f;
- int i=n;
- if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));
- f=toproto(L,-1);
- for (i=0; i<n; i++)
- {
- f->p[i]=toproto(L,i-n-1);
- if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;
- }
- f->sizelineinfo=0;
- return f;
- }
+ if (n==1)
+ return toproto(L,-1);
+ else
+ {
+ Proto* f;
+ int i=n;
+ if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));
+ f=toproto(L,-1);
+ for (i=0; i<n; i++)
+ {
+ f->p[i]=toproto(L,i-n-1);
+ if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;
+ }
+ f->sizelineinfo=0;
+ return f;
+ }
}
static int writer(lua_State* L, const void* p, size_t size, void* u)
{
- UNUSED(L);
- return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
+ UNUSED(L);
+ return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
}
static int pmain(lua_State* L)
{
- int argc=(int)lua_tointeger(L,1);
- char** argv=(char**)lua_touserdata(L,2);
- const Proto* f;
- int i;
- if (!lua_checkstack(L,argc)) fatal("too many input files");
- for (i=0; i<argc; i++)
- {
- const char* filename=IS("-") ? NULL : argv[i];
- if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));
- }
- f=combine(L,argc);
- if (listing) luaU_print(f,listing>1);
- if (dumping)
- {
- FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
- if (D==NULL) cannot("open");
- lua_lock(L);
- luaU_dump(L,f,writer,D,stripping);
- lua_unlock(L);
- if (ferror(D)) cannot("write");
- if (fclose(D)) cannot("close");
- }
- return 0;
+ int argc=(int)lua_tointeger(L,1);
+ char** argv=(char**)lua_touserdata(L,2);
+ const Proto* f;
+ int i;
+ if (!lua_checkstack(L,argc)) fatal("too many input files");
+ for (i=0; i<argc; i++)
+ {
+ const char* filename=IS("-") ? NULL : argv[i];
+ if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));
+ }
+ f=combine(L,argc);
+ if (listing) luaU_print(f,listing>1);
+ if (dumping)
+ {
+ FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
+ if (D==NULL) cannot("open");
+ lua_lock(L);
+ luaU_dump(L,f,writer,D,stripping);
+ lua_unlock(L);
+ if (ferror(D)) cannot("write");
+ if (fclose(D)) cannot("close");
+ }
+ return 0;
}
int main(int argc, char* argv[])
{
- lua_State* L;
- int i=doargs(argc,argv);
- argc-=i; argv+=i;
- if (argc<=0) usage("no input files given");
- L=luaL_newstate();
- if (L==NULL) fatal("cannot create state: not enough memory");
- lua_pushcfunction(L,&pmain);
- lua_pushinteger(L,argc);
- lua_pushlightuserdata(L,argv);
- if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
- lua_close(L);
- return EXIT_SUCCESS;
+ lua_State* L;
+ int i=doargs(argc,argv);
+ argc-=i; argv+=i;
+ if (argc<=0) usage("no input files given");
+ L=luaL_newstate();
+ if (L==NULL) fatal("cannot create state: not enough memory");
+ lua_pushcfunction(L,&pmain);
+ lua_pushinteger(L,argc);
+ lua_pushlightuserdata(L,argv);
+ if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
+ lua_close(L);
+ return EXIT_SUCCESS;
}
/*
@@ -218,215 +218,215 @@ int main(int argc, char* argv[])
#include "lobject.h"
#include "lopcodes.h"
-#define VOID(p) ((const void*)(p))
+#define VOID(p) ((const void*)(p))
static void PrintString(const TString* ts)
{
- const char* s=getstr(ts);
- size_t i,n=ts->tsv.len;
- printf("%c",'"');
- for (i=0; i<n; i++)
- {
- int c=(int)(unsigned char)s[i];
- switch (c)
- {
- case '"': printf("\\\""); break;
- case '\\': printf("\\\\"); break;
- case '\a': printf("\\a"); break;
- case '\b': printf("\\b"); break;
- case '\f': printf("\\f"); break;
- case '\n': printf("\\n"); break;
- case '\r': printf("\\r"); break;
- case '\t': printf("\\t"); break;
- case '\v': printf("\\v"); break;
- default: if (isprint(c))
- printf("%c",c);
+ const char* s=getstr(ts);
+ size_t i,n=ts->tsv.len;
+ printf("%c",'"');
+ for (i=0; i<n; i++)
+ {
+ int c=(int)(unsigned char)s[i];
+ switch (c)
+ {
+ case '"': printf("\\\""); break;
+ case '\\': printf("\\\\"); break;
+ case '\a': printf("\\a"); break;
+ case '\b': printf("\\b"); break;
+ case '\f': printf("\\f"); break;
+ case '\n': printf("\\n"); break;
+ case '\r': printf("\\r"); break;
+ case '\t': printf("\\t"); break;
+ case '\v': printf("\\v"); break;
+ default: if (isprint(c))
+ printf("%c",c);
else
printf("\\%03d",c);
- }
- }
- printf("%c",'"');
+ }
+ }
+ printf("%c",'"');
}
static void PrintConstant(const Proto* f, int i)
{
- const TValue* o=&f->k[i];
- switch (ttype(o))
- {
- case LUA_TNIL:
+ const TValue* o=&f->k[i];
+ switch (ttype(o))
+ {
+ case LUA_TNIL:
printf("nil");
break;
- case LUA_TBOOLEAN:
+ case LUA_TBOOLEAN:
printf(bvalue(o) ? "true" : "false");
break;
- case LUA_TNUMBER:
+ case LUA_TNUMBER:
printf(LUA_NUMBER_FMT,nvalue(o));
break;
- case LUA_TSTRING:
+ case LUA_TSTRING:
PrintString(rawtsvalue(o));
break;
- default: /* cannot happen */
+ default: /* cannot happen */
printf("? type=%d",ttype(o));
break;
- }
+ }
}
#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
-#define MYK(x) (-1-(x))
+#define MYK(x) (-1-(x))
static void PrintCode(const Proto* f)
{
- const Instruction* code=f->code;
- int pc,n=f->sizecode;
- for (pc=0; pc<n; pc++)
- {
- Instruction i=code[pc];
- OpCode o=GET_OPCODE(i);
- int a=GETARG_A(i);
- int b=GETARG_B(i);
- int c=GETARG_C(i);
- int ax=GETARG_Ax(i);
- int bx=GETARG_Bx(i);
- int sbx=GETARG_sBx(i);
- int line=getfuncline(f,pc);
- printf("\t%d\t",pc+1);
- if (line>0) printf("[%d]\t",line); else printf("[-]\t");
- printf("%-9s\t",luaP_opnames[o]);
- switch (getOpMode(o))
- {
- case iABC:
- printf("%d",a);
- if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b);
- if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c);
- break;
- case iABx:
- printf("%d",a);
- if (getBMode(o)==OpArgK) printf(" %d",MYK(bx));
- if (getBMode(o)==OpArgU) printf(" %d",bx);
- break;
- case iAsBx:
- printf("%d %d",a,sbx);
- break;
- case iAx:
- printf("%d",MYK(ax));
- break;
- }
- switch (o)
- {
- case OP_LOADK:
- printf("\t; "); PrintConstant(f,bx);
- break;
- case OP_GETUPVAL:
- case OP_SETUPVAL:
- printf("\t; %s",UPVALNAME(b));
- break;
- case OP_GETTABUP:
- printf("\t; %s",UPVALNAME(b));
- if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
- break;
- case OP_SETTABUP:
- printf("\t; %s",UPVALNAME(a));
- if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
- if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
- break;
- case OP_GETTABLE:
- case OP_SELF:
- if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
- break;
- case OP_SETTABLE:
- case OP_ADD:
- case OP_SUB:
- case OP_MUL:
- case OP_DIV:
- case OP_POW:
- case OP_EQ:
- case OP_LT:
- case OP_LE:
- if (ISK(b) || ISK(c))
- {
- printf("\t; ");
- if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
- printf(" ");
- if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
- }
- break;
- case OP_JMP:
- case OP_FORLOOP:
- case OP_FORPREP:
- case OP_TFORLOOP:
- printf("\t; to %d",sbx+pc+2);
- break;
- case OP_CLOSURE:
- printf("\t; %p",VOID(f->p[bx]));
- break;
- case OP_SETLIST:
- if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c);
- break;
- case OP_EXTRAARG:
- printf("\t; "); PrintConstant(f,ax);
- break;
- default:
- break;
- }
- printf("\n");
- }
+ const Instruction* code=f->code;
+ int pc,n=f->sizecode;
+ for (pc=0; pc<n; pc++)
+ {
+ Instruction i=code[pc];
+ OpCode o=GET_OPCODE(i);
+ int a=GETARG_A(i);
+ int b=GETARG_B(i);
+ int c=GETARG_C(i);
+ int ax=GETARG_Ax(i);
+ int bx=GETARG_Bx(i);
+ int sbx=GETARG_sBx(i);
+ int line=getfuncline(f,pc);
+ printf("\t%d\t",pc+1);
+ if (line>0) printf("[%d]\t",line); else printf("[-]\t");
+ printf("%-9s\t",luaP_opnames[o]);
+ switch (getOpMode(o))
+ {
+ case iABC:
+ printf("%d",a);
+ if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b);
+ if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c);
+ break;
+ case iABx:
+ printf("%d",a);
+ if (getBMode(o)==OpArgK) printf(" %d",MYK(bx));
+ if (getBMode(o)==OpArgU) printf(" %d",bx);
+ break;
+ case iAsBx:
+ printf("%d %d",a,sbx);
+ break;
+ case iAx:
+ printf("%d",MYK(ax));
+ break;
+ }
+ switch (o)
+ {
+ case OP_LOADK:
+ printf("\t; "); PrintConstant(f,bx);
+ break;
+ case OP_GETUPVAL:
+ case OP_SETUPVAL:
+ printf("\t; %s",UPVALNAME(b));
+ break;
+ case OP_GETTABUP:
+ printf("\t; %s",UPVALNAME(b));
+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_SETTABUP:
+ printf("\t; %s",UPVALNAME(a));
+ if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_GETTABLE:
+ case OP_SELF:
+ if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_SETTABLE:
+ case OP_ADD:
+ case OP_SUB:
+ case OP_MUL:
+ case OP_DIV:
+ case OP_POW:
+ case OP_EQ:
+ case OP_LT:
+ case OP_LE:
+ if (ISK(b) || ISK(c))
+ {
+ printf("\t; ");
+ if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
+ printf(" ");
+ if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
+ }
+ break;
+ case OP_JMP:
+ case OP_FORLOOP:
+ case OP_FORPREP:
+ case OP_TFORLOOP:
+ printf("\t; to %d",sbx+pc+2);
+ break;
+ case OP_CLOSURE:
+ printf("\t; %p",VOID(f->p[bx]));
+ break;
+ case OP_SETLIST:
+ if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c);
+ break;
+ case OP_EXTRAARG:
+ printf("\t; "); PrintConstant(f,ax);
+ break;
+ default:
+ break;
+ }
+ printf("\n");
+ }
}
-#define SS(x) ((x==1)?"":"s")
-#define S(x) (int)(x),SS(x)
+#define SS(x) ((x==1)?"":"s")
+#define S(x) (int)(x),SS(x)
static void PrintHeader(const Proto* f)
{
- const char* s=f->source ? getstr(f->source) : "=?";
- if (*s=='@' || *s=='=')
- s++;
- else if (*s==LUA_SIGNATURE[0])
- s="(bstring)";
- else
- s="(string)";
- printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
- (f->linedefined==0)?"main":"function",s,
+ const char* s=f->source ? getstr(f->source) : "=?";
+ if (*s=='@' || *s=='=')
+ s++;
+ else if (*s==LUA_SIGNATURE[0])
+ s="(bstring)";
+ else
+ s="(string)";
+ printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
+ (f->linedefined==0)?"main":"function",s,
f->linedefined,f->lastlinedefined,
S(f->sizecode),VOID(f));
- printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
+ printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
(int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams),
S(f->maxstacksize),S(f->sizeupvalues));
- printf("%d local%s, %d constant%s, %d function%s\n",
+ printf("%d local%s, %d constant%s, %d function%s\n",
S(f->sizelocvars),S(f->sizek),S(f->sizep));
}
static void PrintDebug(const Proto* f)
{
- int i,n;
- n=f->sizek;
- printf("constants (%d) for %p:\n",n,VOID(f));
- for (i=0; i<n; i++)
- {
- printf("\t%d\t",i+1);
- PrintConstant(f,i);
- printf("\n");
- }
- n=f->sizelocvars;
- printf("locals (%d) for %p:\n",n,VOID(f));
- for (i=0; i<n; i++)
- {
- printf("\t%d\t%s\t%d\t%d\n",
- i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
- }
- n=f->sizeupvalues;
- printf("upvalues (%d) for %p:\n",n,VOID(f));
- for (i=0; i<n; i++)
- {
- printf("\t%d\t%s\t%d\t%d\n",
- i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);
- }
+ int i,n;
+ n=f->sizek;
+ printf("constants (%d) for %p:\n",n,VOID(f));
+ for (i=0; i<n; i++)
+ {
+ printf("\t%d\t",i+1);
+ PrintConstant(f,i);
+ printf("\n");
+ }
+ n=f->sizelocvars;
+ printf("locals (%d) for %p:\n",n,VOID(f));
+ for (i=0; i<n; i++)
+ {
+ printf("\t%d\t%s\t%d\t%d\n",
+ i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
+ }
+ n=f->sizeupvalues;
+ printf("upvalues (%d) for %p:\n",n,VOID(f));
+ for (i=0; i<n; i++)
+ {
+ printf("\t%d\t%s\t%d\t%d\n",
+ i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);
+ }
}
static void PrintFunction(const Proto* f, int full)
{
- int i,n=f->sizep;
- PrintHeader(f);
- PrintCode(f);
- if (full) PrintDebug(f);
- for (i=0; i<n; i++) PrintFunction(f->p[i],full);
+ int i,n=f->sizep;
+ PrintHeader(f);
+ PrintCode(f);
+ if (full) PrintDebug(f);
+ for (i=0; i<n; i++) PrintFunction(f->p[i],full);
}
diff --git a/src/lib/lua/luaconf.h b/src/lib/lua/luaconf.h
index df802c9526f..1f55cd1b8f1 100644
--- a/src/lib/lua/luaconf.h
+++ b/src/lib/lua/luaconf.h
@@ -30,32 +30,32 @@
#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
-#define LUA_WIN /* enable goodies for regular Windows platforms */
+#define LUA_WIN /* enable goodies for regular Windows platforms */
#endif
#if defined(LUA_WIN)
#define LUA_DL_DLL
-#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
-#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
-#define LUA_USE_READLINE /* needs some extra libraries */
-#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
-#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
-#define LUA_USE_LONGLONG /* assume support for long long */
+#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
+#define LUA_USE_READLINE /* needs some extra libraries */
+#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_LONGLONG /* assume support for long long */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
-#define LUA_USE_DLOPEN /* does not need -ldl */
-#define LUA_USE_READLINE /* needs an extra library: -lreadline */
-#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
-#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
-#define LUA_USE_LONGLONG /* assume support for long long */
+#define LUA_USE_DLOPEN /* does not need -ldl */
+#define LUA_USE_READLINE /* needs an extra library: -lreadline */
+#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_LONGLONG /* assume support for long long */
#endif
@@ -84,31 +84,31 @@
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
-#if defined(_WIN32) /* { */
+#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
-#define LUA_LDIR "!\\lua\\"
-#define LUA_CDIR "!\\"
+#define LUA_LDIR "!\\lua\\"
+#define LUA_CDIR "!\\"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" ".\\?.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
-#else /* }{ */
+#else /* }{ */
-#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
-#define LUA_ROOT "/usr/local/"
-#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
-#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
+#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
+#define LUA_ROOT "/usr/local/"
+#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
+#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
-#endif /* } */
+#endif /* } */
/*
@@ -117,9 +117,9 @@
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if defined(_WIN32)
-#define LUA_DIRSEP "\\"
+#define LUA_DIRSEP "\\"
#else
-#define LUA_DIRSEP "/"
+#define LUA_DIRSEP "/"
#endif
@@ -128,7 +128,7 @@
@@ environment, used to access global names.
** CHANGE it if you do not like this name.
*/
-#define LUA_ENV "_ENV"
+#define LUA_ENV "_ENV"
/*
@@ -140,24 +140,24 @@
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
-#if defined(LUA_BUILD_AS_DLL) /* { */
+#if defined(LUA_BUILD_AS_DLL) /* { */
-#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
+#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
-#else /* }{ */
+#else /* }{ */
#define LUA_API __declspec(dllimport)
-#endif /* } */
+#endif /* } */
-#else /* }{ */
+#else /* }{ */
-#define LUA_API extern
+#define LUA_API extern
-#endif /* } */
+#endif /* } */
/* more often than not the libs go together with the core */
-#define LUALIB_API LUA_API
-#define LUAMOD_API LUALIB_API
+#define LUALIB_API LUA_API
+#define LUAMOD_API LUALIB_API
/*
@@ -175,16 +175,16 @@
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
- defined(__ELF__) /* { */
-#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
-#define LUAI_DDEC LUAI_FUNC
-#define LUAI_DDEF /* empty */
+ defined(__ELF__) /* { */
+#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
+#define LUAI_DDEC LUAI_FUNC
+#define LUAI_DDEF /* empty */
-#else /* }{ */
-#define LUAI_FUNC extern
-#define LUAI_DDEC extern
-#define LUAI_DDEF /* empty */
-#endif /* } */
+#else /* }{ */
+#define LUAI_FUNC extern
+#define LUAI_DDEC extern
+#define LUAI_DDEF /* empty */
+#endif /* } */
@@ -192,8 +192,8 @@
@@ LUA_QL describes how error messages quote program elements.
** CHANGE it if you want a different appearance.
*/
-#define LUA_QL(x) "'" x "'"
-#define LUA_QS LUA_QL("%s")
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
/*
@@ -201,7 +201,7 @@
@* of a function in debug information.
** CHANGE it if you want a different size.
*/
-#define LUA_IDSIZE 60
+#define LUA_IDSIZE 60
/*
@@ -211,8 +211,8 @@
*/
#if defined(LUA_LIB) || defined(lua_c)
#include <stdio.h>
-#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
-#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
+#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
+#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
#endif
/*
@@ -244,7 +244,7 @@
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
-#if defined(LUA_COMPAT_ALL) /* { */
+#if defined(LUA_COMPAT_ALL) /* { */
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
@@ -264,8 +264,8 @@
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
- lua_pushlightuserdata(L,(u)), \
- lua_pcall(L,1,0,0))
+ lua_pushlightuserdata(L,(u)), \
+ lua_pcall(L,1,0,0))
/*
@@ -290,12 +290,12 @@
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
*/
-#define lua_strlen(L,i) lua_rawlen(L, (i))
+#define lua_strlen(L,i) lua_rawlen(L, (i))
-#define lua_objlen(L,i) lua_rawlen(L, (i))
+#define lua_objlen(L,i) lua_rawlen(L, (i))
-#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
-#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
+#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
+#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
@@ -303,7 +303,7 @@
*/
#define LUA_COMPAT_MODULE
-#endif /* } */
+#endif /* } */
/* }================================================================== */
@@ -315,14 +315,14 @@
** your machine. Probably you do not need to change this.
*/
/* avoid overflows in comparison */
-#if INT_MAX-20 < 32760 /* { */
-#define LUAI_BITSINT 16
-#elif INT_MAX > 2147483640L /* }{ */
+#if INT_MAX-20 < 32760 /* { */
+#define LUAI_BITSINT 16
+#elif INT_MAX > 2147483640L /* }{ */
/* int has at least 32 bits */
-#define LUAI_BITSINT 32
-#else /* }{ */
+#define LUAI_BITSINT 32
+#else /* }{ */
#error "you must define LUA_BITSINT with number of bits in an integer"
-#endif /* } */
+#endif /* } */
/*
@@ -335,16 +335,16 @@
** good enough for your machine. Probably you do not need to change
** this.
*/
-#if LUAI_BITSINT >= 32 /* { */
-#define LUA_INT32 int
-#define LUAI_UMEM size_t
-#define LUAI_MEM ptrdiff_t
-#else /* }{ */
+#if LUAI_BITSINT >= 32 /* { */
+#define LUA_INT32 int
+#define LUAI_UMEM size_t
+#define LUAI_MEM ptrdiff_t
+#else /* }{ */
/* 16-bit ints */
-#define LUA_INT32 long
-#define LUAI_UMEM unsigned long
-#define LUAI_MEM long
-#endif /* } */
+#define LUA_INT32 long
+#define LUAI_UMEM unsigned long
+#define LUAI_MEM long
+#endif /* } */
/*
@@ -354,13 +354,13 @@
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32
-#define LUAI_MAXSTACK 1000000
+#define LUAI_MAXSTACK 1000000
#else
-#define LUAI_MAXSTACK 15000
+#define LUAI_MAXSTACK 15000
#endif
/* reserve some space for error handling */
-#define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
+#define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
@@ -369,7 +369,7 @@
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space.
*/
-#define LUAL_BUFFERSIZE BUFSIZ
+#define LUAL_BUFFERSIZE BUFSIZ
@@ -384,13 +384,13 @@
*/
#define LUA_NUMBER_DOUBLE
-#define LUA_NUMBER double
+#define LUA_NUMBER double
/*
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
*/
-#define LUAI_UACNUMBER double
+#define LUAI_UACNUMBER double
/*
@@ -399,16 +399,16 @@
@@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
*/
-#define LUA_NUMBER_SCAN "%lf"
-#define LUA_NUMBER_FMT "%.14g"
-#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
-#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
+#define LUA_NUMBER_SCAN "%lf"
+#define LUA_NUMBER_FMT "%.14g"
+#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
/*
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations
*/
-#define l_mathop(x) (x)
+#define l_mathop(x) (x)
/*
@@ -419,10 +419,10 @@
** systems, you can leave 'lua_strx2number' undefined and Lua will
** provide its own implementation.
*/
-#define lua_str2number(s,p) strtod((s), (p))
+#define lua_str2number(s,p) strtod((s), (p))
#if defined(LUA_USE_STRTODHEX)
-#define lua_strx2number(s,p) strtod((s), (p))
+#define lua_strx2number(s,p) strtod((s), (p))
#endif
@@ -433,21 +433,21 @@
/* the following operations need the math library */
#if defined(lobject_c) || defined(lvm_c)
#include <math.h>
-#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
-#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
+#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
+#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
#endif
/* these are quite standard operations */
#if defined(LUA_CORE)
-#define luai_numadd(L,a,b) ((a)+(b))
-#define luai_numsub(L,a,b) ((a)-(b))
-#define luai_nummul(L,a,b) ((a)*(b))
-#define luai_numdiv(L,a,b) ((a)/(b))
-#define luai_numunm(L,a) (-(a))
-#define luai_numeq(a,b) ((a)==(b))
-#define luai_numlt(L,a,b) ((a)<(b))
-#define luai_numle(L,a,b) ((a)<=(b))
-#define luai_numisnan(L,a) (!luai_numeq((a), (a)))
+#define luai_numadd(L,a,b) ((a)+(b))
+#define luai_numsub(L,a,b) ((a)-(b))
+#define luai_nummul(L,a,b) ((a)*(b))
+#define luai_numdiv(L,a,b) ((a)/(b))
+#define luai_numunm(L,a) (-(a))
+#define luai_numeq(a,b) ((a)==(b))
+#define luai_numlt(L,a,b) ((a)<(b))
+#define luai_numle(L,a,b) ((a)<=(b))
+#define luai_numisnan(L,a) (!luai_numeq((a), (a)))
#endif
@@ -457,13 +457,13 @@
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
*/
-#define LUA_INTEGER ptrdiff_t
+#define LUA_INTEGER ptrdiff_t
/*
@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
** It must have at least 32 bits.
*/
-#define LUA_UNSIGNED unsigned LUA_INT32
+#define LUA_UNSIGNED unsigned LUA_INT32
@@ -471,7 +471,7 @@
** Some tricks with doubles
*/
-#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
+#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
/*
** The next definitions activate some tricks to speed up the
** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
@@ -498,10 +498,10 @@
*/
/* Microsoft compiler on a Pentium (32 bit) ? */
-#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
+#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
#define LUA_MSASMTRICK
-#define LUA_IEEEENDIAN 0
+#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK
@@ -510,28 +510,28 @@
#define LUA_IEEE754TRICK
#define LUA_IEEELL
-#define LUA_IEEEENDIAN 0
+#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK
/* pentium 64 bits? */
-#elif defined(__x86_64) /* }{ */
+#elif defined(__x86_64) /* }{ */
#define LUA_IEEE754TRICK
-#define LUA_IEEEENDIAN 0
+#define LUA_IEEEENDIAN 0
-#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
+#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
#define LUA_IEEE754TRICK
-#define LUA_IEEEENDIAN 1
+#define LUA_IEEEENDIAN 1
-#else /* }{ */
+#else /* }{ */
/* assume IEEE754 and a 32-bit integer type */
#define LUA_IEEE754TRICK
-#endif /* } */
+#endif /* } */
-#endif /* } */
+#endif /* } */
/* }================================================================== */
@@ -548,4 +548,3 @@
#endif
-
diff --git a/src/lib/lua/lualib.h b/src/lib/lua/lualib.h
index 9fd126bf78e..d6b9d7ee68c 100644
--- a/src/lib/lua/lualib.h
+++ b/src/lib/lua/lualib.h
@@ -14,31 +14,31 @@
LUAMOD_API int (luaopen_base) (lua_State *L);
-#define LUA_COLIBNAME "coroutine"
+#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
-#define LUA_TABLIBNAME "table"
+#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
-#define LUA_IOLIBNAME "io"
+#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
-#define LUA_OSLIBNAME "os"
+#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
-#define LUA_STRLIBNAME "string"
+#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
-#define LUA_BITLIBNAME "bit32"
+#define LUA_BITLIBNAME "bit32"
LUAMOD_API int (luaopen_bit32) (lua_State *L);
-#define LUA_MATHLIBNAME "math"
+#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
-#define LUA_DBLIBNAME "debug"
+#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
-#define LUA_LOADLIBNAME "package"
+#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
@@ -48,7 +48,7 @@ LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
-#define lua_assert(x) ((void)0)
+#define lua_assert(x) ((void)0)
#endif
diff --git a/src/lib/lua/lundump.c b/src/lib/lua/lundump.c
index 54de011a45d..f39aa227735 100644
--- a/src/lib/lua/lundump.c
+++ b/src/lib/lua/lundump.c
@@ -21,183 +21,183 @@
#include "lzio.h"
typedef struct {
- lua_State* L;
- ZIO* Z;
- Mbuffer* b;
- const char* name;
+ lua_State* L;
+ ZIO* Z;
+ Mbuffer* b;
+ const char* name;
} LoadState;
static l_noret error(LoadState* S, const char* why)
{
- luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
- luaD_throw(S->L,LUA_ERRSYNTAX);
+ luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
+ luaD_throw(S->L,LUA_ERRSYNTAX);
}
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
-#define LoadByte(S) (lu_byte)LoadChar(S)
-#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
-#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
+#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
+#define LoadByte(S) (lu_byte)LoadChar(S)
+#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
+#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
#if !defined(luai_verifycode)
-#define luai_verifycode(L,b,f) /* empty */
+#define luai_verifycode(L,b,f) /* empty */
#endif
static void LoadBlock(LoadState* S, void* b, size_t size)
{
- if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
+ if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
}
static int LoadChar(LoadState* S)
{
- char x;
- LoadVar(S,x);
- return x;
+ char x;
+ LoadVar(S,x);
+ return x;
}
static int LoadInt(LoadState* S)
{
- int x;
- LoadVar(S,x);
- if (x<0) error(S,"corrupted");
- return x;
+ int x;
+ LoadVar(S,x);
+ if (x<0) error(S,"corrupted");
+ return x;
}
static lua_Number LoadNumber(LoadState* S)
{
- lua_Number x;
- LoadVar(S,x);
- return x;
+ lua_Number x;
+ LoadVar(S,x);
+ return x;
}
static TString* LoadString(LoadState* S)
{
- size_t size;
- LoadVar(S,size);
- if (size==0)
- return NULL;
- else
- {
- char* s=luaZ_openspace(S->L,S->b,size);
- LoadBlock(S,s,size*sizeof(char));
- return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
- }
+ size_t size;
+ LoadVar(S,size);
+ if (size==0)
+ return NULL;
+ else
+ {
+ char* s=luaZ_openspace(S->L,S->b,size);
+ LoadBlock(S,s,size*sizeof(char));
+ return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
+ }
}
static void LoadCode(LoadState* S, Proto* f)
{
- int n=LoadInt(S);
- f->code=luaM_newvector(S->L,n,Instruction);
- f->sizecode=n;
- LoadVector(S,f->code,n,sizeof(Instruction));
+ int n=LoadInt(S);
+ f->code=luaM_newvector(S->L,n,Instruction);
+ f->sizecode=n;
+ LoadVector(S,f->code,n,sizeof(Instruction));
}
static void LoadFunction(LoadState* S, Proto* f);
static void LoadConstants(LoadState* S, Proto* f)
{
- int i,n;
- n=LoadInt(S);
- f->k=luaM_newvector(S->L,n,TValue);
- f->sizek=n;
- for (i=0; i<n; i++) setnilvalue(&f->k[i]);
- for (i=0; i<n; i++)
- {
- TValue* o=&f->k[i];
- int t=LoadChar(S);
- switch (t)
- {
- case LUA_TNIL:
+ int i,n;
+ n=LoadInt(S);
+ f->k=luaM_newvector(S->L,n,TValue);
+ f->sizek=n;
+ for (i=0; i<n; i++) setnilvalue(&f->k[i]);
+ for (i=0; i<n; i++)
+ {
+ TValue* o=&f->k[i];
+ int t=LoadChar(S);
+ switch (t)
+ {
+ case LUA_TNIL:
setnilvalue(o);
break;
- case LUA_TBOOLEAN:
+ case LUA_TBOOLEAN:
setbvalue(o,LoadChar(S));
break;
- case LUA_TNUMBER:
+ case LUA_TNUMBER:
setnvalue(o,LoadNumber(S));
break;
- case LUA_TSTRING:
+ case LUA_TSTRING:
setsvalue2n(S->L,o,LoadString(S));
break;
- default: lua_assert(0);
- }
- }
- n=LoadInt(S);
- f->p=luaM_newvector(S->L,n,Proto*);
- f->sizep=n;
- for (i=0; i<n; i++) f->p[i]=NULL;
- for (i=0; i<n; i++)
- {
- f->p[i]=luaF_newproto(S->L);
- LoadFunction(S,f->p[i]);
- }
+ default: lua_assert(0);
+ }
+ }
+ n=LoadInt(S);
+ f->p=luaM_newvector(S->L,n,Proto*);
+ f->sizep=n;
+ for (i=0; i<n; i++) f->p[i]=NULL;
+ for (i=0; i<n; i++)
+ {
+ f->p[i]=luaF_newproto(S->L);
+ LoadFunction(S,f->p[i]);
+ }
}
static void LoadUpvalues(LoadState* S, Proto* f)
{
- int i,n;
- n=LoadInt(S);
- f->upvalues=luaM_newvector(S->L,n,Upvaldesc);
- f->sizeupvalues=n;
- for (i=0; i<n; i++) f->upvalues[i].name=NULL;
- for (i=0; i<n; i++)
- {
- f->upvalues[i].instack=LoadByte(S);
- f->upvalues[i].idx=LoadByte(S);
- }
+ int i,n;
+ n=LoadInt(S);
+ f->upvalues=luaM_newvector(S->L,n,Upvaldesc);
+ f->sizeupvalues=n;
+ for (i=0; i<n; i++) f->upvalues[i].name=NULL;
+ for (i=0; i<n; i++)
+ {
+ f->upvalues[i].instack=LoadByte(S);
+ f->upvalues[i].idx=LoadByte(S);
+ }
}
static void LoadDebug(LoadState* S, Proto* f)
{
- int i,n;
- f->source=LoadString(S);
- n=LoadInt(S);
- f->lineinfo=luaM_newvector(S->L,n,int);
- f->sizelineinfo=n;
- LoadVector(S,f->lineinfo,n,sizeof(int));
- n=LoadInt(S);
- f->locvars=luaM_newvector(S->L,n,LocVar);
- f->sizelocvars=n;
- for (i=0; i<n; i++) f->locvars[i].varname=NULL;
- for (i=0; i<n; i++)
- {
- f->locvars[i].varname=LoadString(S);
- f->locvars[i].startpc=LoadInt(S);
- f->locvars[i].endpc=LoadInt(S);
- }
- n=LoadInt(S);
- for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
+ int i,n;
+ f->source=LoadString(S);
+ n=LoadInt(S);
+ f->lineinfo=luaM_newvector(S->L,n,int);
+ f->sizelineinfo=n;
+ LoadVector(S,f->lineinfo,n,sizeof(int));
+ n=LoadInt(S);
+ f->locvars=luaM_newvector(S->L,n,LocVar);
+ f->sizelocvars=n;
+ for (i=0; i<n; i++) f->locvars[i].varname=NULL;
+ for (i=0; i<n; i++)
+ {
+ f->locvars[i].varname=LoadString(S);
+ f->locvars[i].startpc=LoadInt(S);
+ f->locvars[i].endpc=LoadInt(S);
+ }
+ n=LoadInt(S);
+ for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
}
static void LoadFunction(LoadState* S, Proto* f)
{
- f->linedefined=LoadInt(S);
- f->lastlinedefined=LoadInt(S);
- f->numparams=LoadByte(S);
- f->is_vararg=LoadByte(S);
- f->maxstacksize=LoadByte(S);
- LoadCode(S,f);
- LoadConstants(S,f);
- LoadUpvalues(S,f);
- LoadDebug(S,f);
+ f->linedefined=LoadInt(S);
+ f->lastlinedefined=LoadInt(S);
+ f->numparams=LoadByte(S);
+ f->is_vararg=LoadByte(S);
+ f->maxstacksize=LoadByte(S);
+ LoadCode(S,f);
+ LoadConstants(S,f);
+ LoadUpvalues(S,f);
+ LoadDebug(S,f);
}
/* the code below must be consistent with the code in luaU_header */
-#define N0 LUAC_HEADERSIZE
-#define N1 (sizeof(LUA_SIGNATURE)-sizeof(char))
-#define N2 N1+2
-#define N3 N2+6
+#define N0 LUAC_HEADERSIZE
+#define N1 (sizeof(LUA_SIGNATURE)-sizeof(char))
+#define N2 N1+2
+#define N3 N2+6
static void LoadHeader(LoadState* S)
{
- lu_byte h[LUAC_HEADERSIZE];
- lu_byte s[LUAC_HEADERSIZE];
- luaU_header(h);
- memcpy(s,h,sizeof(char)); /* first char already read */
- LoadBlock(S,s+sizeof(char),LUAC_HEADERSIZE-sizeof(char));
- if (memcmp(h,s,N0)==0) return;
- if (memcmp(h,s,N1)!=0) error(S,"not a");
- if (memcmp(h,s,N2)!=0) error(S,"version mismatch in");
- if (memcmp(h,s,N3)!=0) error(S,"incompatible"); else error(S,"corrupted");
+ lu_byte h[LUAC_HEADERSIZE];
+ lu_byte s[LUAC_HEADERSIZE];
+ luaU_header(h);
+ memcpy(s,h,sizeof(char)); /* first char already read */
+ LoadBlock(S,s+sizeof(char),LUAC_HEADERSIZE-sizeof(char));
+ if (memcmp(h,s,N0)==0) return;
+ if (memcmp(h,s,N1)!=0) error(S,"not a");
+ if (memcmp(h,s,N2)!=0) error(S,"version mismatch in");
+ if (memcmp(h,s,N3)!=0) error(S,"incompatible"); else error(S,"corrupted");
}
/*
@@ -205,36 +205,36 @@ static void LoadHeader(LoadState* S)
*/
Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
{
- LoadState S;
- Closure* cl;
- if (*name=='@' || *name=='=')
- S.name=name+1;
- else if (*name==LUA_SIGNATURE[0])
- S.name="binary string";
- else
- S.name=name;
- S.L=L;
- S.Z=Z;
- S.b=buff;
- LoadHeader(&S);
- cl=luaF_newLclosure(L,1);
- setclLvalue(L,L->top,cl); incr_top(L);
- cl->l.p=luaF_newproto(L);
- LoadFunction(&S,cl->l.p);
- if (cl->l.p->sizeupvalues != 1)
- {
- Proto* p=cl->l.p;
- cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
- cl->l.p=p;
- setclLvalue(L,L->top-1,cl);
- }
- luai_verifycode(L,buff,cl->l.p);
- return cl;
+ LoadState S;
+ Closure* cl;
+ if (*name=='@' || *name=='=')
+ S.name=name+1;
+ else if (*name==LUA_SIGNATURE[0])
+ S.name="binary string";
+ else
+ S.name=name;
+ S.L=L;
+ S.Z=Z;
+ S.b=buff;
+ LoadHeader(&S);
+ cl=luaF_newLclosure(L,1);
+ setclLvalue(L,L->top,cl); incr_top(L);
+ cl->l.p=luaF_newproto(L);
+ LoadFunction(&S,cl->l.p);
+ if (cl->l.p->sizeupvalues != 1)
+ {
+ Proto* p=cl->l.p;
+ cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
+ cl->l.p=p;
+ setclLvalue(L,L->top-1,cl);
+ }
+ luai_verifycode(L,buff,cl->l.p);
+ return cl;
}
-#define MYINT(s) (s[0]-'0')
-#define VERSION MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)
-#define FORMAT 0 /* this is the official format */
+#define MYINT(s) (s[0]-'0')
+#define VERSION MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)
+#define FORMAT 0 /* this is the official format */
/*
* make header for precompiled chunks
@@ -243,16 +243,16 @@ Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
*/
void luaU_header (lu_byte* h)
{
- int x=1;
- memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-sizeof(char));
- h+=sizeof(LUA_SIGNATURE)-sizeof(char);
- *h++=cast_byte(VERSION);
- *h++=cast_byte(FORMAT);
- *h++=cast_byte(*(char*)&x); /* endianness */
- *h++=cast_byte(sizeof(int));
- *h++=cast_byte(sizeof(size_t));
- *h++=cast_byte(sizeof(Instruction));
- *h++=cast_byte(sizeof(lua_Number));
- *h++=cast_byte(((lua_Number)0.5)==0); /* is lua_Number integral? */
- memcpy(h,LUAC_TAIL,sizeof(LUAC_TAIL)-sizeof(char));
+ int x=1;
+ memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-sizeof(char));
+ h+=sizeof(LUA_SIGNATURE)-sizeof(char);
+ *h++=cast_byte(VERSION);
+ *h++=cast_byte(FORMAT);
+ *h++=cast_byte(*(char*)&x); /* endianness */
+ *h++=cast_byte(sizeof(int));
+ *h++=cast_byte(sizeof(size_t));
+ *h++=cast_byte(sizeof(Instruction));
+ *h++=cast_byte(sizeof(lua_Number));
+ *h++=cast_byte(((lua_Number)0.5)==0); /* is lua_Number integral? */
+ memcpy(h,LUAC_TAIL,sizeof(LUAC_TAIL)-sizeof(char));
}
diff --git a/src/lib/lua/lundump.h b/src/lib/lua/lundump.h
index 2b8accecb8a..57218253800 100644
--- a/src/lib/lua/lundump.h
+++ b/src/lib/lua/lundump.h
@@ -20,9 +20,9 @@ LUAI_FUNC void luaU_header (lu_byte* h);
LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
/* data to catch conversion errors */
-#define LUAC_TAIL "\x19\x93\r\n\x1a\n"
+#define LUAC_TAIL "\x19\x93\r\n\x1a\n"
/* size in bytes of header of binary files */
-#define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char))
+#define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char))
#endif
diff --git a/src/lib/lua/lvm.c b/src/lib/lua/lvm.c
index a96eedf15eb..46c2f9598d1 100644
--- a/src/lib/lua/lvm.c
+++ b/src/lib/lua/lvm.c
@@ -29,228 +29,228 @@
/* limit for table tag-method chains (to avoid loops) */
-#define MAXTAGLOOP 100
+#define MAXTAGLOOP 100
const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
- lua_Number num;
- if (ttisnumber(obj)) return obj;
- if (ttisstring(obj) && luaO_str2d(svalue(obj), tsvalue(obj)->len, &num)) {
- setnvalue(n, num);
- return n;
- }
- else
- return NULL;
+ lua_Number num;
+ if (ttisnumber(obj)) return obj;
+ if (ttisstring(obj) && luaO_str2d(svalue(obj), tsvalue(obj)->len, &num)) {
+ setnvalue(n, num);
+ return n;
+ }
+ else
+ return NULL;
}
int luaV_tostring (lua_State *L, StkId obj) {
- if (!ttisnumber(obj))
- return 0;
- else {
- char s[LUAI_MAXNUMBER2STR];
- lua_Number n = nvalue(obj);
- int l = lua_number2str(s, n);
- setsvalue2s(L, obj, luaS_newlstr(L, s, l));
- return 1;
- }
+ if (!ttisnumber(obj))
+ return 0;
+ else {
+ char s[LUAI_MAXNUMBER2STR];
+ lua_Number n = nvalue(obj);
+ int l = lua_number2str(s, n);
+ setsvalue2s(L, obj, luaS_newlstr(L, s, l));
+ return 1;
+ }
}
static void traceexec (lua_State *L) {
- CallInfo *ci = L->ci;
- lu_byte mask = L->hookmask;
- int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0);
- if (counthook)
- resethookcount(L); /* reset count */
- if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
- ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
- return; /* do not call hook again (VM yielded, so it did not move) */
- }
- if (counthook)
- luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
- if (mask & LUA_MASKLINE) {
- Proto *p = ci_func(ci)->p;
- int npc = pcRel(ci->u.l.savedpc, p);
- int newline = getfuncline(p, npc);
- if (npc == 0 || /* call linehook when enter a new function, */
- ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */
- newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */
- luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */
- }
- L->oldpc = ci->u.l.savedpc;
- if (L->status == LUA_YIELD) { /* did hook yield? */
- if (counthook)
- L->hookcount = 1; /* undo decrement to zero */
- ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
- ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
- ci->func = L->top - 1; /* protect stack below results */
- luaD_throw(L, LUA_YIELD);
- }
+ CallInfo *ci = L->ci;
+ lu_byte mask = L->hookmask;
+ int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0);
+ if (counthook)
+ resethookcount(L); /* reset count */
+ if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
+ ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
+ return; /* do not call hook again (VM yielded, so it did not move) */
+ }
+ if (counthook)
+ luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
+ if (mask & LUA_MASKLINE) {
+ Proto *p = ci_func(ci)->p;
+ int npc = pcRel(ci->u.l.savedpc, p);
+ int newline = getfuncline(p, npc);
+ if (npc == 0 || /* call linehook when enter a new function, */
+ ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */
+ newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */
+ luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */
+ }
+ L->oldpc = ci->u.l.savedpc;
+ if (L->status == LUA_YIELD) { /* did hook yield? */
+ if (counthook)
+ L->hookcount = 1; /* undo decrement to zero */
+ ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
+ ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
+ ci->func = L->top - 1; /* protect stack below results */
+ luaD_throw(L, LUA_YIELD);
+ }
}
static void callTM (lua_State *L, const TValue *f, const TValue *p1,
- const TValue *p2, TValue *p3, int hasres) {
- ptrdiff_t result = savestack(L, p3);
- setobj2s(L, L->top++, f); /* push function */
- setobj2s(L, L->top++, p1); /* 1st argument */
- setobj2s(L, L->top++, p2); /* 2nd argument */
- if (!hasres) /* no result? 'p3' is third argument */
- setobj2s(L, L->top++, p3); /* 3rd argument */
- /* metamethod may yield only when called from Lua code */
- luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
- if (hasres) { /* if has result, move it to its place */
- p3 = restorestack(L, result);
- setobjs2s(L, p3, --L->top);
- }
+ const TValue *p2, TValue *p3, int hasres) {
+ ptrdiff_t result = savestack(L, p3);
+ setobj2s(L, L->top++, f); /* push function */
+ setobj2s(L, L->top++, p1); /* 1st argument */
+ setobj2s(L, L->top++, p2); /* 2nd argument */
+ if (!hasres) /* no result? 'p3' is third argument */
+ setobj2s(L, L->top++, p3); /* 3rd argument */
+ /* metamethod may yield only when called from Lua code */
+ luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
+ if (hasres) { /* if has result, move it to its place */
+ p3 = restorestack(L, result);
+ setobjs2s(L, p3, --L->top);
+ }
}
void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
- int loop;
- for (loop = 0; loop < MAXTAGLOOP; loop++) {
- const TValue *tm;
- if (ttistable(t)) { /* `t' is a table? */
- Table *h = hvalue(t);
- const TValue *res = luaH_get(h, key); /* do a primitive get */
- if (!ttisnil(res) || /* result is not nil? */
- (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
- setobj2s(L, val, res);
- return;
- }
- /* else will try the tag method */
- }
- else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
- luaG_typeerror(L, t, "index");
- if (ttisfunction(tm)) {
- callTM(L, tm, t, key, val, 1);
- return;
- }
- t = tm; /* else repeat with 'tm' */
- }
- luaG_runerror(L, "loop in gettable");
+ int loop;
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
+ const TValue *tm;
+ if (ttistable(t)) { /* `t' is a table? */
+ Table *h = hvalue(t);
+ const TValue *res = luaH_get(h, key); /* do a primitive get */
+ if (!ttisnil(res) || /* result is not nil? */
+ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
+ setobj2s(L, val, res);
+ return;
+ }
+ /* else will try the tag method */
+ }
+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
+ luaG_typeerror(L, t, "index");
+ if (ttisfunction(tm)) {
+ callTM(L, tm, t, key, val, 1);
+ return;
+ }
+ t = tm; /* else repeat with 'tm' */
+ }
+ luaG_runerror(L, "loop in gettable");
}
void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
- int loop;
- for (loop = 0; loop < MAXTAGLOOP; loop++) {
- const TValue *tm;
- if (ttistable(t)) { /* `t' is a table? */
- Table *h = hvalue(t);
- TValue *oldval = cast(TValue *, luaH_get(h, key));
- /* if previous value is not nil, there must be a previous entry
- in the table; moreover, a metamethod has no relevance */
- if (!ttisnil(oldval) ||
- /* previous value is nil; must check the metamethod */
- ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
- /* no metamethod; is there a previous entry in the table? */
- (oldval != luaO_nilobject ||
- /* no previous entry; must create one. (The next test is
- always true; we only need the assignment.) */
- (oldval = luaH_newkey(L, h, key), 1)))) {
- /* no metamethod and (now) there is an entry with given key */
- setobj2t(L, oldval, val); /* assign new value to that entry */
- invalidateTMcache(h);
- luaC_barrierback(L, obj2gco(h), val);
- return;
- }
- /* else will try the metamethod */
- }
- else /* not a table; check metamethod */
- if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
- luaG_typeerror(L, t, "index");
- /* there is a metamethod */
- if (ttisfunction(tm)) {
- callTM(L, tm, t, key, val, 0);
- return;
- }
- t = tm; /* else repeat with 'tm' */
- }
- luaG_runerror(L, "loop in settable");
+ int loop;
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
+ const TValue *tm;
+ if (ttistable(t)) { /* `t' is a table? */
+ Table *h = hvalue(t);
+ TValue *oldval = cast(TValue *, luaH_get(h, key));
+ /* if previous value is not nil, there must be a previous entry
+ in the table; moreover, a metamethod has no relevance */
+ if (!ttisnil(oldval) ||
+ /* previous value is nil; must check the metamethod */
+ ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
+ /* no metamethod; is there a previous entry in the table? */
+ (oldval != luaO_nilobject ||
+ /* no previous entry; must create one. (The next test is
+ always true; we only need the assignment.) */
+ (oldval = luaH_newkey(L, h, key), 1)))) {
+ /* no metamethod and (now) there is an entry with given key */
+ setobj2t(L, oldval, val); /* assign new value to that entry */
+ invalidateTMcache(h);
+ luaC_barrierback(L, obj2gco(h), val);
+ return;
+ }
+ /* else will try the metamethod */
+ }
+ else /* not a table; check metamethod */
+ if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
+ luaG_typeerror(L, t, "index");
+ /* there is a metamethod */
+ if (ttisfunction(tm)) {
+ callTM(L, tm, t, key, val, 0);
+ return;
+ }
+ t = tm; /* else repeat with 'tm' */
+ }
+ luaG_runerror(L, "loop in settable");
}
static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
- StkId res, TMS event) {
- const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
- if (ttisnil(tm))
- tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
- if (ttisnil(tm)) return 0;
- callTM(L, tm, p1, p2, res, 1);
- return 1;
+ StkId res, TMS event) {
+ const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
+ if (ttisnil(tm))
+ tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
+ if (ttisnil(tm)) return 0;
+ callTM(L, tm, p1, p2, res, 1);
+ return 1;
}
static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2,
- TMS event) {
- const TValue *tm1 = fasttm(L, mt1, event);
- const TValue *tm2;
- if (tm1 == NULL) return NULL; /* no metamethod */
- if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
- tm2 = fasttm(L, mt2, event);
- if (tm2 == NULL) return NULL; /* no metamethod */
- if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */
- return tm1;
- return NULL;
+ TMS event) {
+ const TValue *tm1 = fasttm(L, mt1, event);
+ const TValue *tm2;
+ if (tm1 == NULL) return NULL; /* no metamethod */
+ if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
+ tm2 = fasttm(L, mt2, event);
+ if (tm2 == NULL) return NULL; /* no metamethod */
+ if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */
+ return tm1;
+ return NULL;
}
static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
- TMS event) {
- if (!call_binTM(L, p1, p2, L->top, event))
- return -1; /* no metamethod */
- else
- return !l_isfalse(L->top);
+ TMS event) {
+ if (!call_binTM(L, p1, p2, L->top, event))
+ return -1; /* no metamethod */
+ else
+ return !l_isfalse(L->top);
}
static int l_strcmp (const TString *ls, const TString *rs) {
- const char *l = getstr(ls);
- size_t ll = ls->tsv.len;
- const char *r = getstr(rs);
- size_t lr = rs->tsv.len;
- for (;;) {
- int temp = strcoll(l, r);
- if (temp != 0) return temp;
- else { /* strings are equal up to a `\0' */
- size_t len = strlen(l); /* index of first `\0' in both strings */
- if (len == lr) /* r is finished? */
- return (len == ll) ? 0 : 1;
- else if (len == ll) /* l is finished? */
- return -1; /* l is smaller than r (because r is not finished) */
- /* both strings longer than `len'; go on comparing (after the `\0') */
- len++;
- l += len; ll -= len; r += len; lr -= len;
- }
- }
+ const char *l = getstr(ls);
+ size_t ll = ls->tsv.len;
+ const char *r = getstr(rs);
+ size_t lr = rs->tsv.len;
+ for (;;) {
+ int temp = strcoll(l, r);
+ if (temp != 0) return temp;
+ else { /* strings are equal up to a `\0' */
+ size_t len = strlen(l); /* index of first `\0' in both strings */
+ if (len == lr) /* r is finished? */
+ return (len == ll) ? 0 : 1;
+ else if (len == ll) /* l is finished? */
+ return -1; /* l is smaller than r (because r is not finished) */
+ /* both strings longer than `len'; go on comparing (after the `\0') */
+ len++;
+ l += len; ll -= len; r += len; lr -= len;
+ }
+ }
}
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
- int res;
- if (ttisnumber(l) && ttisnumber(r))
- return luai_numlt(L, nvalue(l), nvalue(r));
- else if (ttisstring(l) && ttisstring(r))
- return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
- else if ((res = call_orderTM(L, l, r, TM_LT)) < 0)
- luaG_ordererror(L, l, r);
- return res;
+ int res;
+ if (ttisnumber(l) && ttisnumber(r))
+ return luai_numlt(L, nvalue(l), nvalue(r));
+ else if (ttisstring(l) && ttisstring(r))
+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
+ else if ((res = call_orderTM(L, l, r, TM_LT)) < 0)
+ luaG_ordererror(L, l, r);
+ return res;
}
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
- int res;
- if (ttisnumber(l) && ttisnumber(r))
- return luai_numle(L, nvalue(l), nvalue(r));
- else if (ttisstring(l) && ttisstring(r))
- return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
- else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */
- return res;
- else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */
- luaG_ordererror(L, l, r);
- return !res;
+ int res;
+ if (ttisnumber(l) && ttisnumber(r))
+ return luai_numle(L, nvalue(l), nvalue(r));
+ else if (ttisstring(l) && ttisstring(r))
+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
+ else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */
+ return res;
+ else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */
+ luaG_ordererror(L, l, r);
+ return !res;
}
@@ -258,116 +258,116 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
** equality of Lua values. L == NULL means raw equality (no metamethods)
*/
int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
- const TValue *tm;
- lua_assert(ttisequal(t1, t2));
- switch (ttype(t1)) {
- case LUA_TNIL: return 1;
- case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
- case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
- case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
- case LUA_TLCF: return fvalue(t1) == fvalue(t2);
- case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2));
- case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2));
- case LUA_TUSERDATA: {
- if (uvalue(t1) == uvalue(t2)) return 1;
- else if (L == NULL) return 0;
- tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
- break; /* will try TM */
- }
- case LUA_TTABLE: {
- if (hvalue(t1) == hvalue(t2)) return 1;
- else if (L == NULL) return 0;
- tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
- break; /* will try TM */
- }
- default:
- lua_assert(iscollectable(t1));
- return gcvalue(t1) == gcvalue(t2);
- }
- if (tm == NULL) return 0; /* no TM? */
- callTM(L, tm, t1, t2, L->top, 1); /* call TM */
- return !l_isfalse(L->top);
+ const TValue *tm;
+ lua_assert(ttisequal(t1, t2));
+ switch (ttype(t1)) {
+ case LUA_TNIL: return 1;
+ case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
+ case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
+ case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
+ case LUA_TLCF: return fvalue(t1) == fvalue(t2);
+ case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2));
+ case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2));
+ case LUA_TUSERDATA: {
+ if (uvalue(t1) == uvalue(t2)) return 1;
+ else if (L == NULL) return 0;
+ tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
+ break; /* will try TM */
+ }
+ case LUA_TTABLE: {
+ if (hvalue(t1) == hvalue(t2)) return 1;
+ else if (L == NULL) return 0;
+ tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
+ break; /* will try TM */
+ }
+ default:
+ lua_assert(iscollectable(t1));
+ return gcvalue(t1) == gcvalue(t2);
+ }
+ if (tm == NULL) return 0; /* no TM? */
+ callTM(L, tm, t1, t2, L->top, 1); /* call TM */
+ return !l_isfalse(L->top);
}
void luaV_concat (lua_State *L, int total) {
- lua_assert(total >= 2);
- do {
- StkId top = L->top;
- int n = 2; /* number of elements handled in this pass (at least 2) */
- if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
- if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
- luaG_concaterror(L, top-2, top-1);
- }
- else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
- (void)tostring(L, top - 2); /* result is first operand */
- else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
- setobjs2s(L, top - 2, top - 1); /* result is second op. */
- }
- else {
- /* at least two non-empty string values; get as many as possible */
- size_t tl = tsvalue(top-1)->len;
- char *buffer;
- int i;
- /* collect total length */
- for (i = 1; i < total && tostring(L, top-i-1); i++) {
- size_t l = tsvalue(top-i-1)->len;
- if (l >= (MAX_SIZET/sizeof(char)) - tl)
- luaG_runerror(L, "string length overflow");
- tl += l;
- }
- buffer = luaZ_openspace(L, &G(L)->buff, tl);
- tl = 0;
- n = i;
- do { /* concat all strings */
- size_t l = tsvalue(top-i)->len;
- memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
- tl += l;
- } while (--i > 0);
- setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
- }
- total -= n-1; /* got 'n' strings to create 1 new */
- L->top -= n-1; /* popped 'n' strings and pushed one */
- } while (total > 1); /* repeat until only 1 result left */
+ lua_assert(total >= 2);
+ do {
+ StkId top = L->top;
+ int n = 2; /* number of elements handled in this pass (at least 2) */
+ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
+ if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
+ luaG_concaterror(L, top-2, top-1);
+ }
+ else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
+ (void)tostring(L, top - 2); /* result is first operand */
+ else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
+ setobjs2s(L, top - 2, top - 1); /* result is second op. */
+ }
+ else {
+ /* at least two non-empty string values; get as many as possible */
+ size_t tl = tsvalue(top-1)->len;
+ char *buffer;
+ int i;
+ /* collect total length */
+ for (i = 1; i < total && tostring(L, top-i-1); i++) {
+ size_t l = tsvalue(top-i-1)->len;
+ if (l >= (MAX_SIZET/sizeof(char)) - tl)
+ luaG_runerror(L, "string length overflow");
+ tl += l;
+ }
+ buffer = luaZ_openspace(L, &G(L)->buff, tl);
+ tl = 0;
+ n = i;
+ do { /* concat all strings */
+ size_t l = tsvalue(top-i)->len;
+ memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
+ tl += l;
+ } while (--i > 0);
+ setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
+ }
+ total -= n-1; /* got 'n' strings to create 1 new */
+ L->top -= n-1; /* popped 'n' strings and pushed one */
+ } while (total > 1); /* repeat until only 1 result left */
}
void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
- const TValue *tm;
- switch (ttypenv(rb)) {
- case LUA_TTABLE: {
- Table *h = hvalue(rb);
- tm = fasttm(L, h->metatable, TM_LEN);
- if (tm) break; /* metamethod? break switch to call it */
- setnvalue(ra, cast_num(1.0*luaH_getn(h))); /* else primitive len */
- return;
- }
- case LUA_TSTRING: {
- setnvalue(ra, cast_num(tsvalue(rb)->len));
- return;
- }
- default: { /* try metamethod */
- tm = luaT_gettmbyobj(L, rb, TM_LEN);
- if (ttisnil(tm)) /* no metamethod? */
- luaG_typeerror(L, rb, "get length of");
- break;
- }
- }
- callTM(L, tm, rb, rb, ra, 1);
+ const TValue *tm;
+ switch (ttypenv(rb)) {
+ case LUA_TTABLE: {
+ Table *h = hvalue(rb);
+ tm = fasttm(L, h->metatable, TM_LEN);
+ if (tm) break; /* metamethod? break switch to call it */
+ setnvalue(ra, cast_num(1.0*luaH_getn(h))); /* else primitive len */
+ return;
+ }
+ case LUA_TSTRING: {
+ setnvalue(ra, cast_num(tsvalue(rb)->len));
+ return;
+ }
+ default: { /* try metamethod */
+ tm = luaT_gettmbyobj(L, rb, TM_LEN);
+ if (ttisnil(tm)) /* no metamethod? */
+ luaG_typeerror(L, rb, "get length of");
+ break;
+ }
+ }
+ callTM(L, tm, rb, rb, ra, 1);
}
void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
- const TValue *rc, TMS op) {
- TValue tempb, tempc;
- const TValue *b, *c;
- if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
- (c = luaV_tonumber(rc, &tempc)) != NULL) {
- lua_Number res = luaO_arith(op - TM_ADD + LUA_OPADD, nvalue(b), nvalue(c));
- setnvalue(ra, res);
- }
- else if (!call_binTM(L, rb, rc, ra, op))
- luaG_aritherror(L, rb, rc);
+ const TValue *rc, TMS op) {
+ TValue tempb, tempc;
+ const TValue *b, *c;
+ if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
+ (c = luaV_tonumber(rc, &tempc)) != NULL) {
+ lua_Number res = luaO_arith(op - TM_ADD + LUA_OPADD, nvalue(b), nvalue(c));
+ setnvalue(ra, res);
+ }
+ else if (!call_binTM(L, rb, rc, ra, op))
+ luaG_aritherror(L, rb, rc);
}
@@ -377,18 +377,18 @@ void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
** new closure to be created.
*/
static Closure *getcached (Proto *p, UpVal **encup, StkId base) {
- Closure *c = p->cache;
- if (c != NULL) { /* is there a cached closure? */
- int nup = p->sizeupvalues;
- Upvaldesc *uv = p->upvalues;
- int i;
- for (i = 0; i < nup; i++) { /* check whether it has right upvalues */
- TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;
- if (c->l.upvals[i]->v != v)
- return NULL; /* wrong upvalue; cannot reuse closure */
- }
- }
- return c; /* return cached closure (or NULL if no cached closure) */
+ Closure *c = p->cache;
+ if (c != NULL) { /* is there a cached closure? */
+ int nup = p->sizeupvalues;
+ Upvaldesc *uv = p->upvalues;
+ int i;
+ for (i = 0; i < nup; i++) { /* check whether it has right upvalues */
+ TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;
+ if (c->l.upvals[i]->v != v)
+ return NULL; /* wrong upvalue; cannot reuse closure */
+ }
+ }
+ return c; /* return cached closure (or NULL if no cached closure) */
}
@@ -399,21 +399,21 @@ static Closure *getcached (Proto *p, UpVal **encup, StkId base) {
** original value of that field.
*/
static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
- StkId ra) {
- int nup = p->sizeupvalues;
- Upvaldesc *uv = p->upvalues;
- int i;
- Closure *ncl = luaF_newLclosure(L, nup);
- ncl->l.p = p;
- setclLvalue(L, ra, ncl); /* anchor new closure in stack */
- for (i = 0; i < nup; i++) { /* fill in its upvalues */
- if (uv[i].instack) /* upvalue refers to local variable? */
- ncl->l.upvals[i] = luaF_findupval(L, base + uv[i].idx);
- else /* get upvalue from enclosing function */
- ncl->l.upvals[i] = encup[uv[i].idx];
- }
- luaC_barrierproto(L, p, ncl);
- p->cache = ncl; /* save it on cache for reuse */
+ StkId ra) {
+ int nup = p->sizeupvalues;
+ Upvaldesc *uv = p->upvalues;
+ int i;
+ Closure *ncl = luaF_newLclosure(L, nup);
+ ncl->l.p = p;
+ setclLvalue(L, ra, ncl); /* anchor new closure in stack */
+ for (i = 0; i < nup; i++) { /* fill in its upvalues */
+ if (uv[i].instack) /* upvalue refers to local variable? */
+ ncl->l.upvals[i] = luaF_findupval(L, base + uv[i].idx);
+ else /* get upvalue from enclosing function */
+ ncl->l.upvals[i] = encup[uv[i].idx];
+ }
+ luaC_barrierproto(L, p, ncl);
+ p->cache = ncl; /* save it on cache for reuse */
}
@@ -421,58 +421,58 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
** finish execution of an opcode interrupted by an yield
*/
void luaV_finishOp (lua_State *L) {
- CallInfo *ci = L->ci;
- StkId base = ci->u.l.base;
- Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
- OpCode op = GET_OPCODE(inst);
- switch (op) { /* finish its execution */
- case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
- case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
- case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
- setobjs2s(L, base + GETARG_A(inst), --L->top);
- break;
- }
- case OP_LE: case OP_LT: case OP_EQ: {
- int res = !l_isfalse(L->top - 1);
- L->top--;
- /* metamethod should not be called when operand is K */
- lua_assert(!ISK(GETARG_B(inst)));
- if (op == OP_LE && /* "<=" using "<" instead? */
- ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
- res = !res; /* invert result */
- lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
- if (res != GETARG_A(inst)) /* condition failed? */
- ci->u.l.savedpc++; /* skip jump instruction */
- break;
- }
- case OP_CONCAT: {
- StkId top = L->top - 1; /* top when 'call_binTM' was called */
- int b = GETARG_B(inst); /* first element to concatenate */
- int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */
- setobj2s(L, top - 2, top); /* put TM result in proper position */
- if (total > 1) { /* are there elements to concat? */
- L->top = top - 1; /* top is one after last element (at top-2) */
- luaV_concat(L, total); /* concat them (may yield again) */
- }
- /* move final result to final position */
- setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);
- L->top = ci->top; /* restore top */
- break;
- }
- case OP_TFORCALL: {
- lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);
- L->top = ci->top; /* correct top */
- break;
- }
- case OP_CALL: {
- if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */
- L->top = ci->top; /* adjust results */
- break;
- }
- case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
- break;
- default: lua_assert(0);
- }
+ CallInfo *ci = L->ci;
+ StkId base = ci->u.l.base;
+ Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
+ OpCode op = GET_OPCODE(inst);
+ switch (op) { /* finish its execution */
+ case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
+ case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
+ case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
+ setobjs2s(L, base + GETARG_A(inst), --L->top);
+ break;
+ }
+ case OP_LE: case OP_LT: case OP_EQ: {
+ int res = !l_isfalse(L->top - 1);
+ L->top--;
+ /* metamethod should not be called when operand is K */
+ lua_assert(!ISK(GETARG_B(inst)));
+ if (op == OP_LE && /* "<=" using "<" instead? */
+ ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
+ res = !res; /* invert result */
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
+ if (res != GETARG_A(inst)) /* condition failed? */
+ ci->u.l.savedpc++; /* skip jump instruction */
+ break;
+ }
+ case OP_CONCAT: {
+ StkId top = L->top - 1; /* top when 'call_binTM' was called */
+ int b = GETARG_B(inst); /* first element to concatenate */
+ int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */
+ setobj2s(L, top - 2, top); /* put TM result in proper position */
+ if (total > 1) { /* are there elements to concat? */
+ L->top = top - 1; /* top is one after last element (at top-2) */
+ luaV_concat(L, total); /* concat them (may yield again) */
+ }
+ /* move final result to final position */
+ setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);
+ L->top = ci->top; /* restore top */
+ break;
+ }
+ case OP_TFORCALL: {
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);
+ L->top = ci->top; /* correct top */
+ break;
+ }
+ case OP_CALL: {
+ if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */
+ L->top = ci->top; /* adjust results */
+ break;
+ }
+ case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
+ break;
+ default: lua_assert(0);
+ }
}
@@ -482,386 +482,385 @@ void luaV_finishOp (lua_State *L) {
*/
#if !defined luai_runtimecheck
-#define luai_runtimecheck(L, c) /* void */
+#define luai_runtimecheck(L, c) /* void */
#endif
-#define RA(i) (base+GETARG_A(i))
+#define RA(i) (base+GETARG_A(i))
/* to be used after possible stack reallocation */
-#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
-#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
-#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
+#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
+#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
+#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
-#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
+#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
#define KBx(i) \
- (k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
+ (k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
/* execute a jump instruction */
#define dojump(ci,i,e) \
- { int a = GETARG_A(i); \
- if (a > 0) luaF_close(L, ci->u.l.base + a - 1); \
- ci->u.l.savedpc += GETARG_sBx(i) + e; }
+ { int a = GETARG_A(i); \
+ if (a > 0) luaF_close(L, ci->u.l.base + a - 1); \
+ ci->u.l.savedpc += GETARG_sBx(i) + e; }
/* for test instructions, execute the jump instruction that follows it */
-#define donextjump(ci) { i = *ci->u.l.savedpc; dojump(ci, i, 1); }
+#define donextjump(ci) { i = *ci->u.l.savedpc; dojump(ci, i, 1); }
-#define Protect(x) { {x;}; base = ci->u.l.base; }
+#define Protect(x) { {x;}; base = ci->u.l.base; }
#define checkGC(L,c) \
- Protect( luaC_condGC(L,{L->top = (c); /* limit of live values */ \
- luaC_step(L); \
- L->top = ci->top;}) /* restore top */ \
- luai_threadyield(L); )
+ Protect( luaC_condGC(L,{L->top = (c); /* limit of live values */ \
+ luaC_step(L); \
+ L->top = ci->top;}) /* restore top */ \
+ luai_threadyield(L); )
#define arith_op(op,tm) { \
- TValue *rb = RKB(i); \
- TValue *rc = RKC(i); \
- if (ttisnumber(rb) && ttisnumber(rc)) { \
- lua_Number nb = nvalue(rb), nc = nvalue(rc); \
- setnvalue(ra, op(L, nb, nc)); \
- } \
- else { Protect(luaV_arith(L, ra, rb, rc, tm)); } }
+ TValue *rb = RKB(i); \
+ TValue *rc = RKC(i); \
+ if (ttisnumber(rb) && ttisnumber(rc)) { \
+ lua_Number nb = nvalue(rb), nc = nvalue(rc); \
+ setnvalue(ra, op(L, nb, nc)); \
+ } \
+ else { Protect(luaV_arith(L, ra, rb, rc, tm)); } }
-#define vmdispatch(o) switch(o)
-#define vmcase(l,b) case l: {b} break;
-#define vmcasenb(l,b) case l: {b} /* nb = no break */
+#define vmdispatch(o) switch(o)
+#define vmcase(l,b) case l: {b} break;
+#define vmcasenb(l,b) case l: {b} /* nb = no break */
void luaV_execute (lua_State *L) {
- CallInfo *ci = L->ci;
- LClosure *cl;
- TValue *k;
- StkId base;
- newframe: /* reentry point when frame changes (call/return) */
- lua_assert(ci == L->ci);
- cl = clLvalue(ci->func);
- k = cl->p->k;
- base = ci->u.l.base;
- /* main loop of interpreter */
- for (;;) {
- Instruction i = *(ci->u.l.savedpc++);
- StkId ra;
- if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
- (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
- Protect(traceexec(L));
- }
- /* WARNING: several calls may realloc the stack and invalidate `ra' */
- ra = RA(i);
- lua_assert(base == ci->u.l.base);
- lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
- vmdispatch (GET_OPCODE(i)) {
- vmcase(OP_MOVE,
- setobjs2s(L, ra, RB(i));
- )
- vmcase(OP_LOADK,
- TValue *rb = k + GETARG_Bx(i);
- setobj2s(L, ra, rb);
- )
- vmcase(OP_LOADKX,
- TValue *rb;
- lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
- rb = k + GETARG_Ax(*ci->u.l.savedpc++);
- setobj2s(L, ra, rb);
- )
- vmcase(OP_LOADBOOL,
- setbvalue(ra, GETARG_B(i));
- if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */
- )
- vmcase(OP_LOADNIL,
- int b = GETARG_B(i);
- do {
- setnilvalue(ra++);
- } while (b--);
- )
- vmcase(OP_GETUPVAL,
- int b = GETARG_B(i);
- setobj2s(L, ra, cl->upvals[b]->v);
- )
- vmcase(OP_GETTABUP,
- int b = GETARG_B(i);
- Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
- )
- vmcase(OP_GETTABLE,
- Protect(luaV_gettable(L, RB(i), RKC(i), ra));
- )
- vmcase(OP_SETTABUP,
- int a = GETARG_A(i);
- Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
- )
- vmcase(OP_SETUPVAL,
- UpVal *uv = cl->upvals[GETARG_B(i)];
- setobj(L, uv->v, ra);
- luaC_barrier(L, uv, ra);
- )
- vmcase(OP_SETTABLE,
- Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
- )
- vmcase(OP_NEWTABLE,
- int b = GETARG_B(i);
- int c = GETARG_C(i);
- Table *t = luaH_new(L);
- sethvalue(L, ra, t);
- if (b != 0 || c != 0)
- luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
- checkGC(L, ra + 1);
- )
- vmcase(OP_SELF,
- StkId rb = RB(i);
- setobjs2s(L, ra+1, rb);
- Protect(luaV_gettable(L, rb, RKC(i), ra));
- )
- vmcase(OP_ADD,
- arith_op(luai_numadd, TM_ADD);
- )
- vmcase(OP_SUB,
- arith_op(luai_numsub, TM_SUB);
- )
- vmcase(OP_MUL,
- arith_op(luai_nummul, TM_MUL);
- )
- vmcase(OP_DIV,
- arith_op(luai_numdiv, TM_DIV);
- )
- vmcase(OP_MOD,
- arith_op(luai_nummod, TM_MOD);
- )
- vmcase(OP_POW,
- arith_op(luai_numpow, TM_POW);
- )
- vmcase(OP_UNM,
- TValue *rb = RB(i);
- if (ttisnumber(rb)) {
- lua_Number nb = nvalue(rb);
- setnvalue(ra, luai_numunm(L, nb));
- }
- else {
- Protect(luaV_arith(L, ra, rb, rb, TM_UNM));
- }
- )
- vmcase(OP_NOT,
- TValue *rb = RB(i);
- int res = l_isfalse(rb); /* next assignment may change this value */
- setbvalue(ra, res);
- )
- vmcase(OP_LEN,
- Protect(luaV_objlen(L, ra, RB(i)));
- )
- vmcase(OP_CONCAT,
- int b = GETARG_B(i);
- int c = GETARG_C(i);
- StkId rb;
- L->top = base + c + 1; /* mark the end of concat operands */
- Protect(luaV_concat(L, c - b + 1));
- ra = RA(i); /* 'luav_concat' may invoke TMs and move the stack */
- rb = b + base;
- setobjs2s(L, ra, rb);
- checkGC(L, (ra >= rb ? ra + 1 : rb));
- L->top = ci->top; /* restore top */
- )
- vmcase(OP_JMP,
- dojump(ci, i, 0);
- )
- vmcase(OP_EQ,
- TValue *rb = RKB(i);
- TValue *rc = RKC(i);
- Protect(
- if (cast_int(equalobj(L, rb, rc)) != GETARG_A(i))
- ci->u.l.savedpc++;
- else
- donextjump(ci);
- )
- )
- vmcase(OP_LT,
- Protect(
- if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))
- ci->u.l.savedpc++;
- else
- donextjump(ci);
- )
- )
- vmcase(OP_LE,
- Protect(
- if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))
- ci->u.l.savedpc++;
- else
- donextjump(ci);
- )
- )
- vmcase(OP_TEST,
- if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))
- ci->u.l.savedpc++;
- else
- donextjump(ci);
- )
- vmcase(OP_TESTSET,
- TValue *rb = RB(i);
- if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))
- ci->u.l.savedpc++;
- else {
- setobjs2s(L, ra, rb);
- donextjump(ci);
- }
- )
- vmcase(OP_CALL,
- int b = GETARG_B(i);
- int nresults = GETARG_C(i) - 1;
- if (b != 0) L->top = ra+b; /* else previous instruction set top */
- if (luaD_precall(L, ra, nresults)) { /* C function? */
- if (nresults >= 0) L->top = ci->top; /* adjust results */
- base = ci->u.l.base;
- }
- else { /* Lua function */
- ci = L->ci;
- ci->callstatus |= CIST_REENTRY;
- goto newframe; /* restart luaV_execute over new Lua function */
- }
- )
- vmcase(OP_TAILCALL,
- int b = GETARG_B(i);
- if (b != 0) L->top = ra+b; /* else previous instruction set top */
- lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
- if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
- base = ci->u.l.base;
- else {
- /* tail call: put called frame (n) in place of caller one (o) */
- CallInfo *nci = L->ci; /* called frame */
- CallInfo *oci = nci->previous; /* caller frame */
- StkId nfunc = nci->func; /* called function */
- StkId ofunc = oci->func; /* caller function */
- /* last stack slot filled by 'precall' */
- StkId lim = nci->u.l.base + getproto(nfunc)->numparams;
- int aux;
- /* close all upvalues from previous call */
- if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);
- /* move new frame into old one */
- for (aux = 0; nfunc + aux < lim; aux++)
- setobjs2s(L, ofunc + aux, nfunc + aux);
- oci->u.l.base = ofunc + (nci->u.l.base - nfunc); /* correct base */
- oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */
- oci->u.l.savedpc = nci->u.l.savedpc;
- oci->callstatus |= CIST_TAIL; /* function was tail called */
- ci = L->ci = oci; /* remove new frame */
- lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);
- goto newframe; /* restart luaV_execute over new Lua function */
- }
- )
- vmcasenb(OP_RETURN,
- int b = GETARG_B(i);
- if (b != 0) L->top = ra+b-1;
- if (cl->p->sizep > 0) luaF_close(L, base);
- b = luaD_poscall(L, ra);
- if (!(ci->callstatus & CIST_REENTRY)) /* 'ci' still the called one */
- return; /* external invocation: return */
- else { /* invocation via reentry: continue execution */
- ci = L->ci;
- if (b) L->top = ci->top;
- lua_assert(isLua(ci));
- lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);
- goto newframe; /* restart luaV_execute over new Lua function */
- }
- )
- vmcase(OP_FORLOOP,
- lua_Number step = nvalue(ra+2);
- lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */
- lua_Number limit = nvalue(ra+1);
- if (luai_numlt(L, 0, step) ? luai_numle(L, idx, limit)
- : luai_numle(L, limit, idx)) {
- ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
- setnvalue(ra, idx); /* update internal index... */
- setnvalue(ra+3, idx); /* ...and external index */
- }
- )
- vmcase(OP_FORPREP,
- const TValue *init = ra;
- const TValue *plimit = ra+1;
- const TValue *pstep = ra+2;
- if (!tonumber(init, ra))
- luaG_runerror(L, LUA_QL("for") " initial value must be a number");
- else if (!tonumber(plimit, ra+1))
- luaG_runerror(L, LUA_QL("for") " limit must be a number");
- else if (!tonumber(pstep, ra+2))
- luaG_runerror(L, LUA_QL("for") " step must be a number");
- setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));
- ci->u.l.savedpc += GETARG_sBx(i);
- )
- vmcasenb(OP_TFORCALL,
- StkId cb = ra + 3; /* call base */
- setobjs2s(L, cb+2, ra+2);
- setobjs2s(L, cb+1, ra+1);
- setobjs2s(L, cb, ra);
- L->top = cb + 3; /* func. + 2 args (state and index) */
- Protect(luaD_call(L, cb, GETARG_C(i), 1));
- L->top = ci->top;
- i = *(ci->u.l.savedpc++); /* go to next instruction */
- ra = RA(i);
- lua_assert(GET_OPCODE(i) == OP_TFORLOOP);
- goto l_tforloop;
- )
- vmcase(OP_TFORLOOP,
- l_tforloop:
- if (!ttisnil(ra + 1)) { /* continue loop? */
- setobjs2s(L, ra, ra + 1); /* save control variable */
- ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
- }
- )
- vmcase(OP_SETLIST,
- int n = GETARG_B(i);
- int c = GETARG_C(i);
- int last;
- Table *h;
- if (n == 0) n = cast_int(L->top - ra) - 1;
- if (c == 0) {
- lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
- c = GETARG_Ax(*ci->u.l.savedpc++);
- }
- luai_runtimecheck(L, ttistable(ra));
- h = hvalue(ra);
- last = ((c-1)*LFIELDS_PER_FLUSH) + n;
- if (last > h->sizearray) /* needs more space? */
- luaH_resizearray(L, h, last); /* pre-allocate it at once */
- for (; n > 0; n--) {
- TValue *val = ra+n;
- luaH_setint(L, h, last--, val);
- luaC_barrierback(L, obj2gco(h), val);
- }
- L->top = ci->top; /* correct top (in case of previous open call) */
- )
- vmcase(OP_CLOSURE,
- Proto *p = cl->p->p[GETARG_Bx(i)];
- Closure *ncl = getcached(p, cl->upvals, base); /* cached closure */
- if (ncl == NULL) /* no match? */
- pushclosure(L, p, cl->upvals, base, ra); /* create a new one */
- else
- setclLvalue(L, ra, ncl); /* push cashed closure */
- checkGC(L, ra + 1);
- )
- vmcase(OP_VARARG,
- int b = GETARG_B(i) - 1;
- int j;
- int n = cast_int(base - ci->func) - cl->p->numparams - 1;
- if (b < 0) { /* B == 0? */
- b = n; /* get all var. arguments */
- Protect(luaD_checkstack(L, n));
- ra = RA(i); /* previous call may change the stack */
- L->top = ra + n;
- }
- for (j = 0; j < b; j++) {
- if (j < n) {
- setobjs2s(L, ra + j, base - n + j);
- }
- else {
- setnilvalue(ra + j);
- }
- }
- )
- vmcase(OP_EXTRAARG,
- lua_assert(0);
- )
- }
- }
+ CallInfo *ci = L->ci;
+ LClosure *cl;
+ TValue *k;
+ StkId base;
+ newframe: /* reentry point when frame changes (call/return) */
+ lua_assert(ci == L->ci);
+ cl = clLvalue(ci->func);
+ k = cl->p->k;
+ base = ci->u.l.base;
+ /* main loop of interpreter */
+ for (;;) {
+ Instruction i = *(ci->u.l.savedpc++);
+ StkId ra;
+ if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
+ (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
+ Protect(traceexec(L));
+ }
+ /* WARNING: several calls may realloc the stack and invalidate `ra' */
+ ra = RA(i);
+ lua_assert(base == ci->u.l.base);
+ lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
+ vmdispatch (GET_OPCODE(i)) {
+ vmcase(OP_MOVE,
+ setobjs2s(L, ra, RB(i));
+ )
+ vmcase(OP_LOADK,
+ TValue *rb = k + GETARG_Bx(i);
+ setobj2s(L, ra, rb);
+ )
+ vmcase(OP_LOADKX,
+ TValue *rb;
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
+ rb = k + GETARG_Ax(*ci->u.l.savedpc++);
+ setobj2s(L, ra, rb);
+ )
+ vmcase(OP_LOADBOOL,
+ setbvalue(ra, GETARG_B(i));
+ if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */
+ )
+ vmcase(OP_LOADNIL,
+ int b = GETARG_B(i);
+ do {
+ setnilvalue(ra++);
+ } while (b--);
+ )
+ vmcase(OP_GETUPVAL,
+ int b = GETARG_B(i);
+ setobj2s(L, ra, cl->upvals[b]->v);
+ )
+ vmcase(OP_GETTABUP,
+ int b = GETARG_B(i);
+ Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
+ )
+ vmcase(OP_GETTABLE,
+ Protect(luaV_gettable(L, RB(i), RKC(i), ra));
+ )
+ vmcase(OP_SETTABUP,
+ int a = GETARG_A(i);
+ Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
+ )
+ vmcase(OP_SETUPVAL,
+ UpVal *uv = cl->upvals[GETARG_B(i)];
+ setobj(L, uv->v, ra);
+ luaC_barrier(L, uv, ra);
+ )
+ vmcase(OP_SETTABLE,
+ Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
+ )
+ vmcase(OP_NEWTABLE,
+ int b = GETARG_B(i);
+ int c = GETARG_C(i);
+ Table *t = luaH_new(L);
+ sethvalue(L, ra, t);
+ if (b != 0 || c != 0)
+ luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
+ checkGC(L, ra + 1);
+ )
+ vmcase(OP_SELF,
+ StkId rb = RB(i);
+ setobjs2s(L, ra+1, rb);
+ Protect(luaV_gettable(L, rb, RKC(i), ra));
+ )
+ vmcase(OP_ADD,
+ arith_op(luai_numadd, TM_ADD);
+ )
+ vmcase(OP_SUB,
+ arith_op(luai_numsub, TM_SUB);
+ )
+ vmcase(OP_MUL,
+ arith_op(luai_nummul, TM_MUL);
+ )
+ vmcase(OP_DIV,
+ arith_op(luai_numdiv, TM_DIV);
+ )
+ vmcase(OP_MOD,
+ arith_op(luai_nummod, TM_MOD);
+ )
+ vmcase(OP_POW,
+ arith_op(luai_numpow, TM_POW);
+ )
+ vmcase(OP_UNM,
+ TValue *rb = RB(i);
+ if (ttisnumber(rb)) {
+ lua_Number nb = nvalue(rb);
+ setnvalue(ra, luai_numunm(L, nb));
+ }
+ else {
+ Protect(luaV_arith(L, ra, rb, rb, TM_UNM));
+ }
+ )
+ vmcase(OP_NOT,
+ TValue *rb = RB(i);
+ int res = l_isfalse(rb); /* next assignment may change this value */
+ setbvalue(ra, res);
+ )
+ vmcase(OP_LEN,
+ Protect(luaV_objlen(L, ra, RB(i)));
+ )
+ vmcase(OP_CONCAT,
+ int b = GETARG_B(i);
+ int c = GETARG_C(i);
+ StkId rb;
+ L->top = base + c + 1; /* mark the end of concat operands */
+ Protect(luaV_concat(L, c - b + 1));
+ ra = RA(i); /* 'luav_concat' may invoke TMs and move the stack */
+ rb = b + base;
+ setobjs2s(L, ra, rb);
+ checkGC(L, (ra >= rb ? ra + 1 : rb));
+ L->top = ci->top; /* restore top */
+ )
+ vmcase(OP_JMP,
+ dojump(ci, i, 0);
+ )
+ vmcase(OP_EQ,
+ TValue *rb = RKB(i);
+ TValue *rc = RKC(i);
+ Protect(
+ if (cast_int(equalobj(L, rb, rc)) != GETARG_A(i))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ )
+ vmcase(OP_LT,
+ Protect(
+ if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ )
+ vmcase(OP_LE,
+ Protect(
+ if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ )
+ vmcase(OP_TEST,
+ if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ vmcase(OP_TESTSET,
+ TValue *rb = RB(i);
+ if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))
+ ci->u.l.savedpc++;
+ else {
+ setobjs2s(L, ra, rb);
+ donextjump(ci);
+ }
+ )
+ vmcase(OP_CALL,
+ int b = GETARG_B(i);
+ int nresults = GETARG_C(i) - 1;
+ if (b != 0) L->top = ra+b; /* else previous instruction set top */
+ if (luaD_precall(L, ra, nresults)) { /* C function? */
+ if (nresults >= 0) L->top = ci->top; /* adjust results */
+ base = ci->u.l.base;
+ }
+ else { /* Lua function */
+ ci = L->ci;
+ ci->callstatus |= CIST_REENTRY;
+ goto newframe; /* restart luaV_execute over new Lua function */
+ }
+ )
+ vmcase(OP_TAILCALL,
+ int b = GETARG_B(i);
+ if (b != 0) L->top = ra+b; /* else previous instruction set top */
+ lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
+ if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
+ base = ci->u.l.base;
+ else {
+ /* tail call: put called frame (n) in place of caller one (o) */
+ CallInfo *nci = L->ci; /* called frame */
+ CallInfo *oci = nci->previous; /* caller frame */
+ StkId nfunc = nci->func; /* called function */
+ StkId ofunc = oci->func; /* caller function */
+ /* last stack slot filled by 'precall' */
+ StkId lim = nci->u.l.base + getproto(nfunc)->numparams;
+ int aux;
+ /* close all upvalues from previous call */
+ if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);
+ /* move new frame into old one */
+ for (aux = 0; nfunc + aux < lim; aux++)
+ setobjs2s(L, ofunc + aux, nfunc + aux);
+ oci->u.l.base = ofunc + (nci->u.l.base - nfunc); /* correct base */
+ oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */
+ oci->u.l.savedpc = nci->u.l.savedpc;
+ oci->callstatus |= CIST_TAIL; /* function was tail called */
+ ci = L->ci = oci; /* remove new frame */
+ lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);
+ goto newframe; /* restart luaV_execute over new Lua function */
+ }
+ )
+ vmcasenb(OP_RETURN,
+ int b = GETARG_B(i);
+ if (b != 0) L->top = ra+b-1;
+ if (cl->p->sizep > 0) luaF_close(L, base);
+ b = luaD_poscall(L, ra);
+ if (!(ci->callstatus & CIST_REENTRY)) /* 'ci' still the called one */
+ return; /* external invocation: return */
+ else { /* invocation via reentry: continue execution */
+ ci = L->ci;
+ if (b) L->top = ci->top;
+ lua_assert(isLua(ci));
+ lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);
+ goto newframe; /* restart luaV_execute over new Lua function */
+ }
+ )
+ vmcase(OP_FORLOOP,
+ lua_Number step = nvalue(ra+2);
+ lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */
+ lua_Number limit = nvalue(ra+1);
+ if (luai_numlt(L, 0, step) ? luai_numle(L, idx, limit)
+ : luai_numle(L, limit, idx)) {
+ ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
+ setnvalue(ra, idx); /* update internal index... */
+ setnvalue(ra+3, idx); /* ...and external index */
+ }
+ )
+ vmcase(OP_FORPREP,
+ const TValue *init = ra;
+ const TValue *plimit = ra+1;
+ const TValue *pstep = ra+2;
+ if (!tonumber(init, ra))
+ luaG_runerror(L, LUA_QL("for") " initial value must be a number");
+ else if (!tonumber(plimit, ra+1))
+ luaG_runerror(L, LUA_QL("for") " limit must be a number");
+ else if (!tonumber(pstep, ra+2))
+ luaG_runerror(L, LUA_QL("for") " step must be a number");
+ setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));
+ ci->u.l.savedpc += GETARG_sBx(i);
+ )
+ vmcasenb(OP_TFORCALL,
+ StkId cb = ra + 3; /* call base */
+ setobjs2s(L, cb+2, ra+2);
+ setobjs2s(L, cb+1, ra+1);
+ setobjs2s(L, cb, ra);
+ L->top = cb + 3; /* func. + 2 args (state and index) */
+ Protect(luaD_call(L, cb, GETARG_C(i), 1));
+ L->top = ci->top;
+ i = *(ci->u.l.savedpc++); /* go to next instruction */
+ ra = RA(i);
+ lua_assert(GET_OPCODE(i) == OP_TFORLOOP);
+ goto l_tforloop;
+ )
+ vmcase(OP_TFORLOOP,
+ l_tforloop:
+ if (!ttisnil(ra + 1)) { /* continue loop? */
+ setobjs2s(L, ra, ra + 1); /* save control variable */
+ ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
+ }
+ )
+ vmcase(OP_SETLIST,
+ int n = GETARG_B(i);
+ int c = GETARG_C(i);
+ int last;
+ Table *h;
+ if (n == 0) n = cast_int(L->top - ra) - 1;
+ if (c == 0) {
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
+ c = GETARG_Ax(*ci->u.l.savedpc++);
+ }
+ luai_runtimecheck(L, ttistable(ra));
+ h = hvalue(ra);
+ last = ((c-1)*LFIELDS_PER_FLUSH) + n;
+ if (last > h->sizearray) /* needs more space? */
+ luaH_resizearray(L, h, last); /* pre-allocate it at once */
+ for (; n > 0; n--) {
+ TValue *val = ra+n;
+ luaH_setint(L, h, last--, val);
+ luaC_barrierback(L, obj2gco(h), val);
+ }
+ L->top = ci->top; /* correct top (in case of previous open call) */
+ )
+ vmcase(OP_CLOSURE,
+ Proto *p = cl->p->p[GETARG_Bx(i)];
+ Closure *ncl = getcached(p, cl->upvals, base); /* cached closure */
+ if (ncl == NULL) /* no match? */
+ pushclosure(L, p, cl->upvals, base, ra); /* create a new one */
+ else
+ setclLvalue(L, ra, ncl); /* push cashed closure */
+ checkGC(L, ra + 1);
+ )
+ vmcase(OP_VARARG,
+ int b = GETARG_B(i) - 1;
+ int j;
+ int n = cast_int(base - ci->func) - cl->p->numparams - 1;
+ if (b < 0) { /* B == 0? */
+ b = n; /* get all var. arguments */
+ Protect(luaD_checkstack(L, n));
+ ra = RA(i); /* previous call may change the stack */
+ L->top = ra + n;
+ }
+ for (j = 0; j < b; j++) {
+ if (j < n) {
+ setobjs2s(L, ra + j, base - n + j);
+ }
+ else {
+ setnilvalue(ra + j);
+ }
+ }
+ )
+ vmcase(OP_EXTRAARG,
+ lua_assert(0);
+ )
+ }
+ }
}
-
diff --git a/src/lib/lua/lvm.h b/src/lib/lua/lvm.h
index 07e25f9c64b..2e285f14f08 100644
--- a/src/lib/lua/lvm.h
+++ b/src/lib/lua/lvm.h
@@ -15,11 +15,11 @@
#define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o)))
-#define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL))
+#define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL))
#define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2))
-#define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2)
+#define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2)
/* not to called directly */
@@ -31,14 +31,14 @@ LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
- StkId val);
+ StkId val);
LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
- StkId val);
+ StkId val);
LUAI_FUNC void luaV_finishOp (lua_State *L);
LUAI_FUNC void luaV_execute (lua_State *L);
LUAI_FUNC void luaV_concat (lua_State *L, int total);
LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
- const TValue *rc, TMS op);
+ const TValue *rc, TMS op);
LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
#endif
diff --git a/src/lib/lua/lzio.c b/src/lib/lua/lzio.c
index 8b77054e0b8..e5e825a54e3 100644
--- a/src/lib/lua/lzio.c
+++ b/src/lib/lua/lzio.c
@@ -19,58 +19,56 @@
int luaZ_fill (ZIO *z) {
- size_t size;
- lua_State *L = z->L;
- const char *buff;
- lua_unlock(L);
- buff = z->reader(L, z->data, &size);
- lua_lock(L);
- if (buff == NULL || size == 0)
- return EOZ;
- z->n = size - 1; /* discount char being returned */
- z->p = buff;
- return cast_uchar(*(z->p++));
+ size_t size;
+ lua_State *L = z->L;
+ const char *buff;
+ lua_unlock(L);
+ buff = z->reader(L, z->data, &size);
+ lua_lock(L);
+ if (buff == NULL || size == 0)
+ return EOZ;
+ z->n = size - 1; /* discount char being returned */
+ z->p = buff;
+ return cast_uchar(*(z->p++));
}
void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
- z->L = L;
- z->reader = reader;
- z->data = data;
- z->n = 0;
- z->p = NULL;
+ z->L = L;
+ z->reader = reader;
+ z->data = data;
+ z->n = 0;
+ z->p = NULL;
}
/* --------------------------------------------------------------- read --- */
size_t luaZ_read (ZIO *z, void *b, size_t n) {
- while (n) {
- size_t m;
- if (z->n == 0) { /* no bytes in buffer? */
- if (luaZ_fill(z) == EOZ) /* try to read more */
- return n; /* no more input; return number of missing bytes */
- else {
- z->n++; /* luaZ_fill consumed first byte; put it back */
- z->p--;
- }
- }
- m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
- memcpy(b, z->p, m);
- z->n -= m;
- z->p += m;
- b = (char *)b + m;
- n -= m;
- }
- return 0;
+ while (n) {
+ size_t m;
+ if (z->n == 0) { /* no bytes in buffer? */
+ if (luaZ_fill(z) == EOZ) /* try to read more */
+ return n; /* no more input; return number of missing bytes */
+ else {
+ z->n++; /* luaZ_fill consumed first byte; put it back */
+ z->p--;
+ }
+ }
+ m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
+ memcpy(b, z->p, m);
+ z->n -= m;
+ z->p += m;
+ b = (char *)b + m;
+ n -= m;
+ }
+ return 0;
}
/* ------------------------------------------------------------------------ */
char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
- if (n > buff->buffsize) {
- if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
- luaZ_resizebuffer(L, buff, n);
- }
- return buff->buffer;
+ if (n > buff->buffsize) {
+ if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
+ luaZ_resizebuffer(L, buff, n);
+ }
+ return buff->buffer;
}
-
-
diff --git a/src/lib/lua/lzio.h b/src/lib/lua/lzio.h
index 08682301e8a..3f7ca283bf1 100644
--- a/src/lib/lua/lzio.h
+++ b/src/lib/lua/lzio.h
@@ -13,7 +13,7 @@
#include "lmem.h"
-#define EOZ (-1) /* end of stream */
+#define EOZ (-1) /* end of stream */
typedef struct Zio ZIO;
@@ -21,16 +21,16 @@ typedef struct Zio ZIO;
typedef struct Mbuffer {
- char *buffer;
- size_t n;
- size_t buffsize;
+ char *buffer;
+ size_t n;
+ size_t buffsize;
} Mbuffer;
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
-#define luaZ_buffer(buff) ((buff)->buffer)
-#define luaZ_sizebuffer(buff) ((buff)->buffsize)
-#define luaZ_bufflen(buff) ((buff)->n)
+#define luaZ_buffer(buff) ((buff)->buffer)
+#define luaZ_sizebuffer(buff) ((buff)->buffsize)
+#define luaZ_bufflen(buff) ((buff)->n)
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
@@ -39,24 +39,24 @@ typedef struct Mbuffer {
(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
(buff)->buffsize = size)
-#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
+#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
- void *data);
-LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
+ void *data);
+LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
/* --------- Private Part ------------------ */
struct Zio {
- size_t n; /* bytes still unread */
- const char *p; /* current position in buffer */
- lua_Reader reader; /* reader function */
- void* data; /* additional data */
- lua_State *L; /* Lua state (for reader) */
+ size_t n; /* bytes still unread */
+ const char *p; /* current position in buffer */
+ lua_Reader reader; /* reader function */
+ void* data; /* additional data */
+ lua_State *L; /* Lua state (for reader) */
};
diff --git a/src/lib/util/cdrom.c b/src/lib/util/cdrom.c
index fcf9999eab8..83c5d268445 100644
--- a/src/lib/util/cdrom.c
+++ b/src/lib/util/cdrom.c
@@ -218,20 +218,20 @@ cdrom_file *cdrom_open(const char *inputfile)
physofs += file->cdtoc.tracks[i].frames;
logofs += file->cdtoc.tracks[i].frames;
-/* printf("Track %02d is format %d subtype %d datasize %d subsize %d frames %d extraframes %d pregap %d pgmode %d presize %d postgap %d logofs %d physofs %d chdofs %d\n", i+1,
- file->cdtoc.tracks[i].trktype,
- file->cdtoc.tracks[i].subtype,
- file->cdtoc.tracks[i].datasize,
- file->cdtoc.tracks[i].subsize,
- file->cdtoc.tracks[i].frames,
- file->cdtoc.tracks[i].extraframes,
+/* printf("Track %02d is format %d subtype %d datasize %d subsize %d frames %d extraframes %d pregap %d pgmode %d presize %d postgap %d logofs %d physofs %d chdofs %d\n", i+1,
+ file->cdtoc.tracks[i].trktype,
+ file->cdtoc.tracks[i].subtype,
+ file->cdtoc.tracks[i].datasize,
+ file->cdtoc.tracks[i].subsize,
+ file->cdtoc.tracks[i].frames,
+ file->cdtoc.tracks[i].extraframes,
file->cdtoc.tracks[i].pregap,
- file->cdtoc.tracks[i].pgtype,
- file->cdtoc.tracks[i].pgdatasize,
- file->cdtoc.tracks[i].postgap,
- file->cdtoc.tracks[i].logframeofs,
- file->cdtoc.tracks[i].physframeofs,
- file->cdtoc.tracks[i].chdframeofs);*/
+ file->cdtoc.tracks[i].pgtype,
+ file->cdtoc.tracks[i].pgdatasize,
+ file->cdtoc.tracks[i].postgap,
+ file->cdtoc.tracks[i].logframeofs,
+ file->cdtoc.tracks[i].physframeofs,
+ file->cdtoc.tracks[i].chdframeofs);*/
}
/* fill out dummy entries for the last track to help our search */
@@ -306,20 +306,20 @@ cdrom_file *cdrom_open(chd_file *chd)
chdofs += file->cdtoc.tracks[i].extraframes;
logofs += file->cdtoc.tracks[i].frames;
-/* printf("Track %02d is format %d subtype %d datasize %d subsize %d frames %d extraframes %d pregap %d pgmode %d presize %d postgap %d logofs %d physofs %d chdofs %d\n", i+1,
- file->cdtoc.tracks[i].trktype,
- file->cdtoc.tracks[i].subtype,
- file->cdtoc.tracks[i].datasize,
- file->cdtoc.tracks[i].subsize,
- file->cdtoc.tracks[i].frames,
- file->cdtoc.tracks[i].extraframes,
+/* printf("Track %02d is format %d subtype %d datasize %d subsize %d frames %d extraframes %d pregap %d pgmode %d presize %d postgap %d logofs %d physofs %d chdofs %d\n", i+1,
+ file->cdtoc.tracks[i].trktype,
+ file->cdtoc.tracks[i].subtype,
+ file->cdtoc.tracks[i].datasize,
+ file->cdtoc.tracks[i].subsize,
+ file->cdtoc.tracks[i].frames,
+ file->cdtoc.tracks[i].extraframes,
file->cdtoc.tracks[i].pregap,
- file->cdtoc.tracks[i].pgtype,
- file->cdtoc.tracks[i].pgdatasize,
- file->cdtoc.tracks[i].postgap,
- file->cdtoc.tracks[i].logframeofs,
- file->cdtoc.tracks[i].physframeofs,
- file->cdtoc.tracks[i].chdframeofs);*/
+ file->cdtoc.tracks[i].pgtype,
+ file->cdtoc.tracks[i].pgdatasize,
+ file->cdtoc.tracks[i].postgap,
+ file->cdtoc.tracks[i].logframeofs,
+ file->cdtoc.tracks[i].physframeofs,
+ file->cdtoc.tracks[i].chdframeofs);*/
}
/* fill out dummy entries for the last track to help our search */
@@ -362,7 +362,7 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI
// if this is pregap info that isn't actually in the file, just return blank data
if ((file->cdtoc.tracks[tracknum].pgdatasize == 0) && (lbasector < (file->cdtoc.tracks[tracknum].logframeofs + file->cdtoc.tracks[tracknum].pregap)))
{
-// printf("PG missing sector: LBA %d, trklog %d\n", lbasector, file->cdtoc.tracks[tracknum].logframeofs);
+// printf("PG missing sector: LBA %d, trklog %d\n", lbasector, file->cdtoc.tracks[tracknum].logframeofs);
memset(dest, 0, length);
return CHDERR_NONE;
}
@@ -379,7 +379,7 @@ chd_error read_partial_sector(cdrom_file *file, void *dest, UINT32 lbasector, UI
sourcefileoffset += chdsector * bytespersector + startoffs;
-// printf("Reading sector %d from track %d at offset %lld\n", chdsector, tracknum, sourcefileoffset);
+// printf("Reading sector %d from track %d at offset %lld\n", chdsector, tracknum, sourcefileoffset);
core_fseek(srcfile, sourcefileoffset, SEEK_SET);
core_fread(srcfile, dest, length);
@@ -998,7 +998,7 @@ chd_error cdrom_write_metadata(chd_file *chd, const cdrom_toc *toc)
if (toc->tracks[i].pgdatasize > 0)
{
strcpy(&submode[1], cdrom_get_type_string(toc->tracks[i].pgtype));
- submode[0] = 'V'; // indicate valid submode
+ submode[0] = 'V'; // indicate valid submode
}
else
{
@@ -1322,4 +1322,3 @@ void ecc_clear(UINT8 *sector)
memset(&sector[ECC_P_OFFSET], 0, 2 * ECC_P_NUM_BYTES);
memset(&sector[ECC_Q_OFFSET], 0, 2 * ECC_Q_NUM_BYTES);
}
-
diff --git a/src/lib/util/chdcd.c b/src/lib/util/chdcd.c
index 948d8d1a320..b6835cf9f38 100644
--- a/src/lib/util/chdcd.c
+++ b/src/lib/util/chdcd.c
@@ -868,7 +868,7 @@ chd_error chdcd_parse_cue(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
break;
}
}
- else // pregap sectors not in file, but we're always using idx0ofs for track length calc now
+ else // pregap sectors not in file, but we're always using idx0ofs for track length calc now
{
outinfo.track[trknum].idx0offs = frames;
}
@@ -1175,4 +1175,3 @@ chd_error chdcd_parse_toc(const char *tocfname, cdrom_toc &outtoc, chdcd_track_i
return CHDERR_NONE;
}
-
diff --git a/src/mame/drivers/24cdjuke.c b/src/mame/drivers/24cdjuke.c
index e8ea803d8c0..bd2e7efd821 100644
--- a/src/mame/drivers/24cdjuke.c
+++ b/src/mame/drivers/24cdjuke.c
@@ -3,49 +3,49 @@
Midcoin 24 CD Coin-operated Jukebox
CPUs
-QTY Type clock position function
-1x D780C-1 ic1 8-bit Microprocessor - main
-1x MAB8441T-T042 ic10 8-bit Single Chip Microcontroller - main (internal ROM not dumped)
-3x P8255A-5 ic11,ic25,ic31 Programmable Peripheral Interface
-1x MM5450N ic29 LED Display Driver - main
-2x LM358 ic64,ic65 Dual Operational Amplifier - sound
-1x oscillator 6.0MHz Q1
+QTY Type clock position function
+1x D780C-1 ic1 8-bit Microprocessor - main
+1x MAB8441T-T042 ic10 8-bit Single Chip Microcontroller - main (internal ROM not dumped)
+3x P8255A-5 ic11,ic25,ic31 Programmable Peripheral Interface
+1x MM5450N ic29 LED Display Driver - main
+2x LM358 ic64,ic65 Dual Operational Amplifier - sound
+1x oscillator 6.0MHz Q1
ROMs
-QTY Type position status
-1x D27128D ic5 dumped
-2x M1-7611A-5 ic27,ic28 dumped
-2x DM74LS471N ic20,ic21 dumped
+QTY Type position status
+1x D27128D ic5 dumped
+2x M1-7611A-5 ic27,ic28 dumped
+2x DM74LS471N ic20,ic21 dumped
RAMs
-QTY Type position
-1x HY6116ALP-10 ic22
-1x D43256C-12L ic6
+QTY Type position
+1x HY6116ALP-10 ic22
+1x D43256C-12L ic6
Others
-QTY Type
-1x 6 legs connector (ALIM - power)
-1x 10 pins flat cable connector purple (ALIM DISP - power display)
-1x 10 pins flat cable connector yellow (AMPLI - amplificator)
-1x 10 pins flat cable connector green (MOTORE - engine)
-1x 10 pins flat cable connector black (CD)
-1x 10 pins flat cable connector blu (SERVICE)
-1x 10 pins flat cable connector red (CONTROL MOT - engine control)
-2x jumper (J1 set, RIF unset) 5x trimmer (RP1,RP2,RP4,RP50,RP51)
-2x 8x2 switches DIP (MD1,MD3)
-1x battery 3.6V
-2x red LED (5V,12V)
-4x red LED (CONTR. RAMPA - ramp control - L1,L2,L3,L4)
-8x red LED (HO, BR.D, P.D, D.I, BR.F, P.UP, ENC, MAB)
-1x red LED (5V)
-1x red LED (5V)
-1x red LED (5V)
-1x 16 digits LED display (on solder side), each digit is made by 18 segments
+QTY Type
+1x 6 legs connector (ALIM - power)
+1x 10 pins flat cable connector purple (ALIM DISP - power display)
+1x 10 pins flat cable connector yellow (AMPLI - amplificator)
+1x 10 pins flat cable connector green (MOTORE - engine)
+1x 10 pins flat cable connector black (CD)
+1x 10 pins flat cable connector blu (SERVICE)
+1x 10 pins flat cable connector red (CONTROL MOT - engine control)
+2x jumper (J1 set, RIF unset) 5x trimmer (RP1,RP2,RP4,RP50,RP51)
+2x 8x2 switches DIP (MD1,MD3)
+1x battery 3.6V
+2x red LED (5V,12V)
+4x red LED (CONTR. RAMPA - ramp control - L1,L2,L3,L4)
+8x red LED (HO, BR.D, P.D, D.I, BR.F, P.UP, ENC, MAB)
+1x red LED (5V)
+1x red LED (5V)
+1x red LED (5V)
+1x 16 digits LED display (on solder side), each digit is made by 18 segments
Notes
This is the PCB for one of the first ever CD based Juke Box, made in 1988 by Midcoin, some info here:
-http://www.tilt.it/deb/i-midcoin.html
+http://www.tilt.it/deb/i-midcoin.html
*/
@@ -68,7 +68,7 @@ public:
static ADDRESS_MAP_START( midcoin24cdjuke_map, AS_PROGRAM, 8, midcoin24cdjuke_state )
- AM_RANGE(0x0000, 0x3fff) AM_ROM
+ AM_RANGE(0x0000, 0x3fff) AM_ROM
ADDRESS_MAP_END
@@ -89,22 +89,22 @@ static MACHINE_CONFIG_START( midcoin24cdjuke, midcoin24cdjuke_state )
/* basic machine hardware */
MCFG_CPU_ADD("maincpu", Z80,6000000) /* ? MHz */
MCFG_CPU_PROGRAM_MAP(midcoin24cdjuke_map)
-// MCFG_CPU_VBLANK_INT_DRIVER("screen", midcoin24cdjuke_state, irq0_line_hold)
+// MCFG_CPU_VBLANK_INT_DRIVER("screen", midcoin24cdjuke_state, irq0_line_hold)
MACHINE_CONFIG_END
ROM_START( 24cdjuke )
ROM_REGION( 0x4000, "maincpu", 0 )
- ROM_LOAD( "1.ic5", 0x0000, 0x4000, CRC(df2419ad) SHA1(dd9dd85011d46581dccabcfdb5959a8b018df937) )
+ ROM_LOAD( "1.ic5", 0x0000, 0x4000, CRC(df2419ad) SHA1(dd9dd85011d46581dccabcfdb5959a8b018df937) )
// MAB8441T-T042 internal ROM?
ROM_REGION( 0x80000, "misc", 0 )
- ROM_LOAD( "dm74ls471n.ic20", 0x000, 0x100, CRC(d05765e6) SHA1(119ec6ca1a4afa0ea6ab1020ba2a8b02fd434e3f) )
- ROM_LOAD( "dm74ls471n.ic21", 0x000, 0x100, CRC(e12d5a04) SHA1(be52ee4e4a5ea225fce39c759645a7cf49cea370) )
- ROM_LOAD( "m1-7611a-5.ic27", 0x000, 0x100, CRC(29b068e8) SHA1(477e2445c58b7d14c56a3ad4050eb22474d56005) )
- ROM_LOAD( "m1-7611a-5.ic28", 0x000, 0x100, CRC(29b068e8) SHA1(477e2445c58b7d14c56a3ad4050eb22474d56005) )
+ ROM_LOAD( "dm74ls471n.ic20", 0x000, 0x100, CRC(d05765e6) SHA1(119ec6ca1a4afa0ea6ab1020ba2a8b02fd434e3f) )
+ ROM_LOAD( "dm74ls471n.ic21", 0x000, 0x100, CRC(e12d5a04) SHA1(be52ee4e4a5ea225fce39c759645a7cf49cea370) )
+ ROM_LOAD( "m1-7611a-5.ic27", 0x000, 0x100, CRC(29b068e8) SHA1(477e2445c58b7d14c56a3ad4050eb22474d56005) )
+ ROM_LOAD( "m1-7611a-5.ic28", 0x000, 0x100, CRC(29b068e8) SHA1(477e2445c58b7d14c56a3ad4050eb22474d56005) )
ROM_END
diff --git a/src/mame/drivers/bfm_sc5.c b/src/mame/drivers/bfm_sc5.c
index 99942dd7409..02185973efe 100644
--- a/src/mame/drivers/bfm_sc5.c
+++ b/src/mame/drivers/bfm_sc5.c
@@ -23,7 +23,7 @@
WRITE16_MEMBER( bfm_sc5_state::sc5_duart_w )
{
// clearly a duart of some kind, write patterns are the same as SC4 games
-// printf("%s: duart_w %1x %04x %04x\n", machine().describe_context(), offset, data, mem_mask);
+// printf("%s: duart_w %1x %04x %04x\n", machine().describe_context(), offset, data, mem_mask);
if (mem_mask &0xff00)
{
@@ -104,9 +104,9 @@ static ADDRESS_MAP_START( sc5_map, AS_PROGRAM, 32, bfm_sc5_state )
AM_RANGE(0x010102f0, 0x010102f3) AM_WRITENOP
AM_RANGE(0x01010300, 0x01010303) AM_WRITENOP
-
+
AM_RANGE(0x01010330, 0x01010333) AM_WRITENOP
-
+
AM_RANGE(0x01010360, 0x01010363) AM_WRITENOP
AM_RANGE(0x01010380, 0x01010383) AM_WRITENOP
@@ -132,7 +132,7 @@ static ADDRESS_MAP_START( sc5_map, AS_PROGRAM, 32, bfm_sc5_state )
AM_RANGE(0x010202c0, 0x010202c3) AM_WRITENOP
#endif
AM_RANGE(0x010202F0, 0x010202F3) AM_READWRITE8(sc5_10202F0_r, sc5_10202F0_w, 0xffffffff)
-#if 1
+#if 1
AM_RANGE(0x01020330, 0x01020333) AM_WRITENOP
AM_RANGE(0x01020350, 0x01020353) AM_WRITENOP
diff --git a/src/mame/drivers/bombjack.c b/src/mame/drivers/bombjack.c
index 1d6d141df22..2a2cab7693c 100644
--- a/src/mame/drivers/bombjack.c
+++ b/src/mame/drivers/bombjack.c
@@ -460,25 +460,25 @@ ROM_END
ROM_START( bombjackt )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "9.1j", 0x0000, 0x4000, CRC(4b59a3bb) SHA1(dae45985d2575821c86757ead14b8313e922570d) ) // == 09_j01b.bin + 10_l01b.bin
- ROM_LOAD( "12.1n", 0x4000, 0x4000, CRC(0a32506a) SHA1(2fb3ce695caebbae3ca7dd9f3d34ac5b734d77ed) ) // == 11_m01b.bin + (97.229004%) 12_n01b.bin
- ROM_LOAD( "13.1r", 0xc000, 0x2000, CRC(964ac5c5) SHA1(8d235ae91aea1ae86411671c5aa050c146a52026) ) // (99.877930%) 13_r01b.bin
+ ROM_LOAD( "12.1n", 0x4000, 0x4000, CRC(0a32506a) SHA1(2fb3ce695caebbae3ca7dd9f3d34ac5b734d77ed) ) // == 11_m01b.bin + (97.229004%) 12_n01b.bin
+ ROM_LOAD( "13.1r", 0xc000, 0x2000, CRC(964ac5c5) SHA1(8d235ae91aea1ae86411671c5aa050c146a52026) ) // (99.877930%) 13_r01b.bin
ROM_REGION( 0x10000, "audiocpu", 0 ) /* 64k for sound board */
ROM_LOAD( "1.6h", 0x0000, 0x2000, CRC(8407917d) SHA1(318face9f7a7ab6c7eeac773995040425e780aaf) )
/*
ROM_REGION( 0x3000, "chars", 0 )
- ROM_LOAD( "03_e08t.bin", 0x0000, 0x1000, CRC(9f0470d5) SHA1(94ef52ef47b4399a03528fe3efeac9c1d6983446) )
+ ROM_LOAD( "03_e08t.bin", 0x0000, 0x1000, CRC(9f0470d5) SHA1(94ef52ef47b4399a03528fe3efeac9c1d6983446) )
ROM_LOAD( "04_h08t.bin", 0x1000, 0x1000, CRC(81ec12e6) SHA1(e29ba193f21aa898499187603b25d2e226a07c7b) )
ROM_LOAD( "05_k08t.bin", 0x2000, 0x1000, CRC(e87ec8b1) SHA1(a66808ef2d62fca2854396898b86bac9be5f17a3) )
*/
ROM_REGION( 0x6000, "chars", 0 ) // the Tecfri produced boards apparently use double size roms here (content duplicated in each half)
- ROM_LOAD( "3.1e", 0x0000, 0x2000, CRC(54e1dac1) SHA1(3c5d8b932b2a87acf42e0b4632195776689c1154) )
+ ROM_LOAD( "3.1e", 0x0000, 0x2000, CRC(54e1dac1) SHA1(3c5d8b932b2a87acf42e0b4632195776689c1154) )
ROM_LOAD( "4.1h", 0x2000, 0x2000, CRC(05e428ab) SHA1(0b2cae76aba8372482a4e315a9f49fd15cb94625) )
ROM_LOAD( "5.1k", 0x4000, 0x2000, CRC(f282f29a) SHA1(521a110213d6ecdf54be0f50f41c3c266d65d84c) )
-
+
ROM_REGION( 0x6000, "tiles", 0 ) // ok
ROM_LOAD( "6.1l", 0x0000, 0x2000, CRC(51eebd89) SHA1(515128a3971fcb97b60c5b6bdd2b03026aec1921) ) /* background tiles */
diff --git a/src/mame/drivers/deniam.c b/src/mame/drivers/deniam.c
index 12c002a55b7..635c75ff08e 100644
--- a/src/mame/drivers/deniam.c
+++ b/src/mame/drivers/deniam.c
@@ -227,7 +227,7 @@ WRITE_LINE_MEMBER(deniam_state::irqhandler)
if (m_audiocpu != NULL)
m_audiocpu->set_input_line(0, state);
}
-
+
void deniam_state::machine_start()
diff --git a/src/mame/drivers/dooyong.c b/src/mame/drivers/dooyong.c
index a8fdf6eb132..1df8c5cdd18 100644
--- a/src/mame/drivers/dooyong.c
+++ b/src/mame/drivers/dooyong.c
@@ -616,7 +616,7 @@ INPUT_PORTS_END
static INPUT_PORTS_START( superx )
PORT_INCLUDE( dooyongm68_generic )
- PORT_MODIFY("DSW") /* In documentation this switch enables "service mode" but it never had any effect in game */
+ PORT_MODIFY("DSW") /* In documentation this switch enables "service mode" but it never had any effect in game */
PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SWA:1")
PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
diff --git a/src/mame/drivers/fcrash.c b/src/mame/drivers/fcrash.c
index 22b4204923a..9e1af6c74ab 100644
--- a/src/mame/drivers/fcrash.c
+++ b/src/mame/drivers/fcrash.c
@@ -1727,7 +1727,7 @@ ROM_START( ffightbl )
ROMX_LOAD( "fg-c.bin", 0x000001, 0x80000, CRC(d1dfcd2d) SHA1(8796db70459e1e6232a75f5c3f4bf8b227b16f46) , ROM_SKIP(3) )
ROMX_LOAD( "fg-b.bin", 0x000002, 0x80000, CRC(22f2c097) SHA1(bbf2d30d31c5a7802b7f7f164dd51a4584511936) , ROM_SKIP(3) )
ROMX_LOAD( "fg-a.bin", 0x000003, 0x80000, CRC(16a89b2c) SHA1(4d0e1ec6ae9a2bd31fa77140532bbce64d3874e9) , ROM_SKIP(3) )
-
+
ROM_REGION( 0x8000, "gfx2", 0 )
ROM_COPY( "gfx", 0x000000, 0x000000, 0x8000 ) /* stars */
ROM_END
diff --git a/src/mame/drivers/flstory.c b/src/mame/drivers/flstory.c
index 09cbba8519a..9cf887c2c7e 100644
--- a/src/mame/drivers/flstory.c
+++ b/src/mame/drivers/flstory.c
@@ -873,7 +873,7 @@ static INPUT_PORTS_START( rumba )
PORT_DIPNAME( 0x04, 0x00, DEF_STR( Language ) )
PORT_DIPSETTING( 0x04, DEF_STR( Japanese ) )
PORT_DIPSETTING( 0x00, DEF_STR( English ) )
- PORT_DIPNAME( 0x08, 0x00, "Attract Sound" ) /* At title sequence only - NOT Demo Sounds */
+ PORT_DIPNAME( 0x08, 0x00, "Attract Sound" ) /* At title sequence only - NOT Demo Sounds */
PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x10, 0x00, "Coinage Display" )
diff --git a/src/mame/drivers/fruitpc.c b/src/mame/drivers/fruitpc.c
index f5fd9e8f456..e61eb8cc255 100644
--- a/src/mame/drivers/fruitpc.c
+++ b/src/mame/drivers/fruitpc.c
@@ -354,144 +354,144 @@ static INPUT_PORTS_START( fruitpc )
PORT_START("INP4")
PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNKNOWN )
/*
- PORT_START("IOCARD1")
- PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 )
- PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 )
- PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START1 )
- PORT_DIPNAME( 0x0008, 0x0008, "1" )
- PORT_DIPSETTING( 0x0008, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0010, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0020, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Accelerator")
- PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0080, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
- PORT_START("IOCARD2")
- PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE1 ) // guess
- PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("Reset SW")
- PORT_DIPNAME( 0x0004, 0x0004, "2" )
- PORT_DIPSETTING( 0x0004, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0008, 0x0008, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0008, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0010, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0020, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Turbo")
- PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) // returns back to MS-DOS (likely to be unmapped and actually used as a lame protection check)
- PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
- PORT_START("IOCARD3")
- PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_VBLANK("screen")
- PORT_BIT( 0xdfff, IP_ACTIVE_LOW, IPT_UNUSED )
-
- PORT_START("IOCARD4")
- PORT_DIPNAME( 0x01, 0x01, "DSWA" )
- PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x20, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x0100, 0x0100, "DSWA" )
- PORT_DIPSETTING( 0x0100, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0200, 0x0200, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0200, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0400, 0x0400, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0400, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0800, 0x0800, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0800, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x1000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x4000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x8000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_START("IOCARD5")
- PORT_DIPNAME( 0x01, 0x01, "DSWA" )
- PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x20, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x0100, 0x0100, "DSWA" )
- PORT_DIPSETTING( 0x0100, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0200, 0x0200, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0200, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0400, 0x0400, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0400, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x0800, 0x0800, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x0800, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x1000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x4000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
- PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Unknown ) )
- PORT_DIPSETTING( 0x8000, DEF_STR( Off ) )
- PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_START("IOCARD1")
+ PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 )
+ PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 )
+ PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START1 )
+ PORT_DIPNAME( 0x0008, 0x0008, "1" )
+ PORT_DIPSETTING( 0x0008, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0010, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0020, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Accelerator")
+ PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0080, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
+ PORT_START("IOCARD2")
+ PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE1 ) // guess
+ PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("Reset SW")
+ PORT_DIPNAME( 0x0004, 0x0004, "2" )
+ PORT_DIPSETTING( 0x0004, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0008, 0x0008, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0008, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0010, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0020, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Turbo")
+ PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN ) // returns back to MS-DOS (likely to be unmapped and actually used as a lame protection check)
+ PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
+ PORT_START("IOCARD3")
+ PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_VBLANK("screen")
+ PORT_BIT( 0xdfff, IP_ACTIVE_LOW, IPT_UNUSED )
+
+ PORT_START("IOCARD4")
+ PORT_DIPNAME( 0x01, 0x01, "DSWA" )
+ PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x20, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0100, 0x0100, "DSWA" )
+ PORT_DIPSETTING( 0x0100, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0200, 0x0200, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0200, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0400, 0x0400, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0400, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0800, 0x0800, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0800, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x1000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x4000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x8000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_START("IOCARD5")
+ PORT_DIPNAME( 0x01, 0x01, "DSWA" )
+ PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x20, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x00, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0100, 0x0100, "DSWA" )
+ PORT_DIPSETTING( 0x0100, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0200, 0x0200, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0200, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0400, 0x0400, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0400, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x0800, 0x0800, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x0800, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x1000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x2000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x4000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
+ PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Unknown ) )
+ PORT_DIPSETTING( 0x8000, DEF_STR( Off ) )
+ PORT_DIPSETTING( 0x0000, DEF_STR( On ) )
*/
INPUT_PORTS_END
#endif
diff --git a/src/mame/drivers/galaxian.c b/src/mame/drivers/galaxian.c
index 50467a24ff8..4c349e2da98 100644
--- a/src/mame/drivers/galaxian.c
+++ b/src/mame/drivers/galaxian.c
@@ -1485,8 +1485,8 @@ static ADDRESS_MAP_START( timefgtr_map, AS_PROGRAM, 8, galaxian_state )
AM_RANGE(0xb000, 0xb000) AM_MIRROR(0x07f8) AM_WRITE(irq_enable_w)
AM_RANGE(0xb004, 0xb004) AM_MIRROR(0x07f8) AM_WRITE(galaxian_stars_enable_w)
AM_RANGE(0xb800, 0xb800) AM_MIRROR(0x07ff) AM_READ(watchdog_reset_r)
-// AM_RANGE(0xb800, 0xb800) AM_WRITENOP // ?
-// AM_RANGE(0xfff8, 0xffff) AM_WRITENOP // sound related?
+// AM_RANGE(0xb800, 0xb800) AM_WRITENOP // ?
+// AM_RANGE(0xfff8, 0xffff) AM_WRITENOP // sound related?
ADDRESS_MAP_END
@@ -3283,7 +3283,7 @@ DRIVER_INIT_MEMBER(galaxian_state,fantastc)
DRIVER_INIT_MEMBER(galaxian_state,timefgtr)
{
- /* two sprite generators */
+ /* two sprite generators */
m_numspritegens = 2;
/* bullets moved from $60 to $c0 */
diff --git a/src/mame/drivers/galdrvr.c b/src/mame/drivers/galdrvr.c
index b12fa6354f7..2c13fbf4079 100644
--- a/src/mame/drivers/galdrvr.c
+++ b/src/mame/drivers/galdrvr.c
@@ -59,7 +59,7 @@ static INPUT_PORTS_START( galaxrf )
PORT_DIPSETTING( 0x04, "3" )
PORT_DIPNAME( 0x08, 0x00, "Player Bullet Speed" )
PORT_DIPSETTING( 0x00, "Slow" )
- PORT_DIPSETTING( 0x08, "Fast" )
+ PORT_DIPSETTING( 0x08, "Fast" )
INPUT_PORTS_END
static INPUT_PORTS_START( superg )
@@ -1148,7 +1148,7 @@ static INPUT_PORTS_START( mooncreg )
PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) )
PORT_DIPSETTING( 0x40, DEF_STR( Easy ) )
PORT_DIPSETTING( 0x00, DEF_STR( Hard ) )
- PORT_DIPNAME( 0x80, 0x80, "Player's Bullet Speed" )
+ PORT_DIPNAME( 0x80, 0x80, "Player's Bullet Speed" )
PORT_DIPSETTING( 0x00, "Slow" )
PORT_DIPSETTING( 0x80, "Fast" )
@@ -3850,7 +3850,7 @@ ROM_START( asideral )
ROM_LOAD( "u11.l2", 0x1800, 0x0800, CRC(dcc2b33b) SHA1(c3a5ac935c519400dfabb28909f7e460769d1837) )
ROM_REGION( 0x0020, "proms", 0 ) // which PROM should we be using, the one from the bootlegs or the original UniWarS one, the gfx roms are the same as the original.
-// ROM_LOAD( "l06_prom.bin", 0x0000, 0x0020, CRC(6a0c7d87) SHA1(140335d85c67c75b65689d4e76d29863c209cf32) )
+// ROM_LOAD( "l06_prom.bin", 0x0000, 0x0020, CRC(6a0c7d87) SHA1(140335d85c67c75b65689d4e76d29863c209cf32) )
ROM_LOAD( "uniwars.clr", 0x0000, 0x0020, CRC(25c79518) SHA1(e8f7e8b3d0cf1ed9d723948548f58abf0e2c6d1f) )
ROM_END
diff --git a/src/mame/drivers/goldnpkr.c b/src/mame/drivers/goldnpkr.c
index 805bf150c4f..0ba6010503e 100644
--- a/src/mame/drivers/goldnpkr.c
+++ b/src/mame/drivers/goldnpkr.c
@@ -1299,14 +1299,14 @@ READ8_MEMBER(goldnpkr_state::goldnpkr_mux_port_r)
{
switch( m_mux_data & 0xf0 ) /* bits 4-7 */
{
- /* normal selector writes 7F-BF-DF-EF */
+ /* normal selector writes 7F-BF-DF-EF */
case 0x10: return ioport("IN0-0")->read();
case 0x20: return ioport("IN0-1")->read();
case 0x40: return ioport("IN0-2")->read();
case 0x80: return ioport("IN0-3")->read();
/* royale selector writes 3F-2F-1F-0F.
- worth to split a whole machine driver just for this? */
+ worth to split a whole machine driver just for this? */
case 0xc0: return ioport("IN0-3")->read();
case 0xd0: return ioport("IN0-2")->read();
case 0xe0: return ioport("IN0-1")->read();
@@ -4099,23 +4099,23 @@ ROM_END
/* Videotron Poker.
Only program. No gfx or prom dumps...
- Normal controls.
+ Normal controls.
*/
ROM_START( videtrna )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "poker_videotron.prg", 0x4000, 0x2000, CRC(38494ffb) SHA1(defa03546fd21d854c2d2413e6e2bf575d0518d7) )
ROM_LOAD( "videotron_poker.prg", 0x6000, 0x2000, CRC(960dcb61) SHA1(a7da40383b0149d21156b461c144d345603d747a) )
- ROM_REGION( 0x3000, "gfx1", 0 ) /* taken from videtron */
+ ROM_REGION( 0x3000, "gfx1", 0 ) /* taken from videtron */
ROM_FILL( 0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
ROM_LOAD( "3.bin", 0x2000, 0x0800, BAD_DUMP CRC(23e83e89) SHA1(0c6352d46e3dfe176b0e970dd163e2bc01246890) ) /* text layer */
- ROM_REGION( 0x1800, "gfx2", 0 ) /* taken from videtron */
+ ROM_REGION( 0x1800, "gfx2", 0 ) /* taken from videtron */
ROM_LOAD( "0.bin", 0x0000, 0x0800, BAD_DUMP CRC(1f41c541) SHA1(00df5079193f78db0617a6b8a613d8a0616fc8e9) ) /* cards deck gfx, bitplane1 */
ROM_LOAD( "1.bin", 0x0800, 0x0800, BAD_DUMP CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) ) /* cards deck gfx, bitplane2 */
ROM_LOAD( "2.bin", 0x1000, 0x0800, BAD_DUMP CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) ) /* cards deck gfx, bitplane3 */
- ROM_REGION( 0x0100, "proms", 0 ) /* taken from videtron */
+ ROM_REGION( 0x0100, "proms", 0 ) /* taken from videtron */
ROM_LOAD( "82s129.bin", 0x0000, 0x0100, BAD_DUMP CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
ROM_END
@@ -9708,26 +9708,26 @@ ROM_END
*/
-ROM_START( bchancep ) /* Bonne Chance! with PIAs 6821 */
+ROM_START( bchancep ) /* Bonne Chance! with PIAs 6821 */
ROM_REGION( 0x3000, "gfx", 0 )
- ROM_LOAD( "84.bin", 0x0000, 0x1000, CRC(31f8104e) SHA1(b99f79019517ca90c48e9f303f41256d68faea91) ) /* cards deck gfx bitplane 3, identical halves */
- ROM_LOAD( "85.bin", 0x1000, 0x1000, CRC(40e426af) SHA1(7e7cb30dafc96bcb87a05d3e0ef5c2d426ed6a74) ) /* cards deck gfx bitplane 2, identical halves */
- ROM_LOAD( "87.bin", 0x2000, 0x1000, CRC(79c3578a) SHA1(9f25749f59385e6b80684ba9d4b218eb2a546e8c) ) /* 1st half text layer, 2nd half cards deck gfx bitplane 1 */
+ ROM_LOAD( "84.bin", 0x0000, 0x1000, CRC(31f8104e) SHA1(b99f79019517ca90c48e9f303f41256d68faea91) ) /* cards deck gfx bitplane 3, identical halves */
+ ROM_LOAD( "85.bin", 0x1000, 0x1000, CRC(40e426af) SHA1(7e7cb30dafc96bcb87a05d3e0ef5c2d426ed6a74) ) /* cards deck gfx bitplane 2, identical halves */
+ ROM_LOAD( "87.bin", 0x2000, 0x1000, CRC(79c3578a) SHA1(9f25749f59385e6b80684ba9d4b218eb2a546e8c) ) /* 1st half text layer, 2nd half cards deck gfx bitplane 1 */
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "88.bin", 0x5000, 0x1000, CRC(c617b037) SHA1(55b58496d12dc8bcaa252e8ee847dbcb7d2c417d) )
ROM_LOAD( "89.bin", 0x6000, 0x1000, CRC(15599de0) SHA1(5e7a87dded97ce7829759ed9524809241526b6d8) )
ROM_LOAD( "90.bin", 0x7000, 0x1000, CRC(86690685) SHA1(b8a8039b58f2cdfce77266ac523d87b0d627f213) )
-// ROM_LOAD( "ups39_12a.bin", 0x0000, 0x8000, CRC(216b45fb) SHA1(fbfcd98cc39b2e791cceb845b166ff697f584add) )
+// ROM_LOAD( "ups39_12a.bin", 0x0000, 0x8000, CRC(216b45fb) SHA1(fbfcd98cc39b2e791cceb845b166ff697f584add) )
ROM_REGION( 0x1800, "gfx1", 0 )
ROM_FILL( 0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
- ROM_COPY( "gfx", 0x2000, 0x1000, 0x0800 ) /* text layer and cards logo */
+ ROM_COPY( "gfx", 0x2000, 0x1000, 0x0800 ) /* text layer and cards logo */
ROM_REGION( 0x1800, "gfx2", 0 )
- ROM_COPY( "gfx", 0x0000, 0x0000, 0x0800 ) /* cards deck gfx, bitplane 1 */
- ROM_COPY( "gfx", 0x1000, 0x0800, 0x0800 ) /* cards deck gfx, bitplane 2 */
- ROM_COPY( "gfx", 0x2800, 0x1000, 0x0800 ) /* cards deck gfx, bitplane 3 */
+ ROM_COPY( "gfx", 0x0000, 0x0000, 0x0800 ) /* cards deck gfx, bitplane 1 */
+ ROM_COPY( "gfx", 0x1000, 0x0800, 0x0800 ) /* cards deck gfx, bitplane 2 */
+ ROM_COPY( "gfx", 0x2800, 0x1000, 0x0800 ) /* cards deck gfx, bitplane 3 */
ROM_REGION( 0x0100, "proms", 0 )
ROM_LOAD( "bchancep_bp.bin", 0x0000, 0x0100, CRC(70fe1582) SHA1(118c743d445a37ad760e4163b61c3c562d7adda6) )
@@ -9766,7 +9766,7 @@ ROM_END
*/
ROM_START( pokermon )
- ROM_REGION( 0x18000, "maincpu", 0 ) /* using 1st bank program */
+ ROM_REGION( 0x18000, "maincpu", 0 ) /* using 1st bank program */
ROM_LOAD( "mbv_bi.bin", 0x10000, 0x8000, CRC(da00e08a) SHA1(98e52915178e29ab3ae674e6b895da14626d3dd8) )
ROM_REGION( 0x18000, "gfx", 0 )
@@ -9775,13 +9775,13 @@ ROM_START( pokermon )
ROM_LOAD( "3m.bin", 0x10000, 0x8000, CRC(b2237068) SHA1(ece4f089776bbd5224c63c6a41a2e86a5e89d0c5) )
ROM_REGION( 0x1800, "gfx1", 0 )
- ROM_FILL( 0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
- ROM_COPY( "gfx", 0x14800, 0x1000, 0x0800 ) /* text, numbers and soccer ball tiles */
+ ROM_FILL( 0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
+ ROM_COPY( "gfx", 0x14800, 0x1000, 0x0800 ) /* text, numbers and soccer ball tiles */
ROM_REGION( 0x1800, "gfx2", 0 )
- ROM_COPY( "gfx", 0x00000, 0x0000, 0x0800 ) /* soccer player gfx, bitplane 1 */
- ROM_COPY( "gfx", 0x08000, 0x0800, 0x0800 ) /* soccer player gfx, bitplane 2 */
- ROM_COPY( "gfx", 0x12000, 0x1000, 0x0800 ) /* soccer player gfx, bitplane 3 */
+ ROM_COPY( "gfx", 0x00000, 0x0000, 0x0800 ) /* soccer player gfx, bitplane 1 */
+ ROM_COPY( "gfx", 0x08000, 0x0800, 0x0800 ) /* soccer player gfx, bitplane 2 */
+ ROM_COPY( "gfx", 0x12000, 0x1000, 0x0800 ) /* soccer player gfx, bitplane 3 */
ROM_REGION( 0x0100, "proms", 0 )
ROM_LOAD( "mb.bin", 0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
@@ -10213,11 +10213,11 @@ DRIVER_INIT_MEMBER(goldnpkr_state, mondial)
UINT8 *ROM = memregion("maincpu")->base();
membank("bank1")->configure_entries(0, 2, &ROM[0x10000], 0x4000);
- membank("bank1")->set_entry(0); // for now, fixed in italian.
+ membank("bank1")->set_entry(0); // for now, fixed in italian.
-// UINT8 seldsw = (ioport("SELDSW")->read() );
-// popmessage("ROM Bank: %02X", seldsw);
-// membank("bank1")->set_entry(seldsw);
+// UINT8 seldsw = (ioport("SELDSW")->read() );
+// popmessage("ROM Bank: %02X", seldsw);
+// membank("bank1")->set_entry(seldsw);
}
@@ -10348,14 +10348,14 @@ GAMEL( 1986, brasil86, 0, witchcrd, bsuerte, driver_device, 0,
GAMEL( 1987, brasil87, 0, witchcrd, bsuerte, driver_device, 0, ROT0, "<unknown>", "Brasil 87", 0, layout_goldnpkr )
GAMEL( 1989, brasil89, 0, witchcrd, bsuerte, driver_device, 0, ROT0, "<unknown>", "Brasil 89 (set 1)", 0, layout_goldnpkr )
GAMEL( 1989, brasil89a, brasil89, witchcrd, bsuerte, driver_device, 0, ROT0, "<unknown>", "Brasil 89 (set 2)", 0, layout_goldnpkr )
-GAME( 1993, brasil93, 0, witchcrd, bsuerte, driver_device, 0, ROT0, "<unknown>", "Brasil 93", 0 ) // no lamps
+GAME( 1993, brasil93, 0, witchcrd, bsuerte, driver_device, 0, ROT0, "<unknown>", "Brasil 93", 0 ) // no lamps
GAME( 1991, poker91, 0, witchcrd, poker91, driver_device, 0, ROT0, "<unknown>", "Poker 91", 0 )
GAME( 198?, genie, 0, genie, genie, driver_device, 0, ROT0, "Video Fun Games Ltd.", "Genie", 0 )
GAMEL( 1983, silverga, 0, goldnpkr, goldnpkr, driver_device, 0, ROT0, "<unknown>", "Silver Game", 0, layout_goldnpkr )
GAME( 1987, caspoker, 0, goldnpkr, caspoker, driver_device, 0, ROT0, "PM / Beck Elektronik", "Casino Poker (Ver PM86LO-35-5, German)", GAME_IMPERFECT_COLORS )
-GAME( 198?, pokerdub, 0, pottnpkr, goldnpkr, driver_device, 0, ROT0, "<unknown>", "unknown French poker game", GAME_NOT_WORKING ) // lacks of 2nd program ROM.
-GAME( 198?, pokerduc, 0, goldnpkr, goldnpkr, goldnpkr_state, icp1db, ROT0, "<unknown>", "unknown encrypted poker game", GAME_NOT_WORKING ) // encrypted.
+GAME( 198?, pokerdub, 0, pottnpkr, goldnpkr, driver_device, 0, ROT0, "<unknown>", "unknown French poker game", GAME_NOT_WORKING ) // lacks of 2nd program ROM.
+GAME( 198?, pokerduc, 0, goldnpkr, goldnpkr, goldnpkr_state, icp1db, ROT0, "<unknown>", "unknown encrypted poker game", GAME_NOT_WORKING ) // encrypted.
GAMEL( 198?, bchancep, 0, bchancep, goldnpkr, goldnpkr_state, bchancep, ROT0, "<unknown>", "Bonne Chance! (Golden Poker prequel hardware)", GAME_NOT_WORKING, layout_goldnpkr )
GAME( 1987, pokermon, 0, mondial, mondial, goldnpkr_state, mondial, ROT0, "<unknown>", "Mundial/Mondial (Italian/French)", 0 )
diff --git a/src/mame/drivers/goldstar.c b/src/mame/drivers/goldstar.c
index e73d26f43fb..8d4001b10ef 100644
--- a/src/mame/drivers/goldstar.c
+++ b/src/mame/drivers/goldstar.c
@@ -8608,7 +8608,7 @@ ay-38910A
The program is exactly the same of lucky8d, with 40% for main rate and 60% for d-up,
but merged in only one 27128 EPROM instead of two.
-
+
*/
ROM_START( lucky8e )
@@ -8618,11 +8618,11 @@ ROM_START( lucky8e )
ROM_REGION( 0x18000, "gfx1", 0 )
ROM_LOAD( "27256.5", 0x00000, 0x8000, CRC(59026af3) SHA1(3d7f7e78968ca26275635aeaa0e994468a3da575) )
ROM_LOAD( "27256.6", 0x08000, 0x8000, CRC(67a073c1) SHA1(36194d57d0dc0601fa1fdf2e6806f11b2ea6da36) )
-// ROM_LOAD( "27128.7", 0x10000, 0x4000, BAD_DUMP CRC(0000b9d0) SHA1(00008fe8a116c33bbd712a639224d041447a45c1) )
- ROM_LOAD( "7", 0x10000, 0x8000, CRC(c415b9d0) SHA1(fd558fe8a116c33bbd712a639224d041447a45c1) ) // from pàrent set, since 2 of 3 bitplanes matched
+// ROM_LOAD( "27128.7", 0x10000, 0x4000, BAD_DUMP CRC(0000b9d0) SHA1(00008fe8a116c33bbd712a639224d041447a45c1) )
+ ROM_LOAD( "7", 0x10000, 0x8000, CRC(c415b9d0) SHA1(fd558fe8a116c33bbd712a639224d041447a45c1) ) // from p?rent set, since 2 of 3 bitplanes matched
ROM_REGION( 0x8000, "gfx2", 0 )
- ROM_LOAD( "27128.1", 0x0000, 0x2000, CRC(8ca19ee7) SHA1(2e0cd4a74bd9abef60ed561ba4e5bb2681ce1222) ) // overdump?
+ ROM_LOAD( "27128.1", 0x0000, 0x2000, CRC(8ca19ee7) SHA1(2e0cd4a74bd9abef60ed561ba4e5bb2681ce1222) ) // overdump?
ROM_IGNORE( 0x2000)
ROM_LOAD( "2764.2", 0x2000, 0x2000, CRC(5f812e65) SHA1(70d9ea82f9337936bf21f82b6961768d436f3a6f) )
ROM_LOAD( "2764.3", 0x4000, 0x2000, CRC(898b9ed5) SHA1(11b7d1cfcf425d00d086c74e0dbcb72068dda9fe) )
diff --git a/src/mame/drivers/jpms80.c b/src/mame/drivers/jpms80.c
index 3091f14f01c..a9a6515f438 100644
--- a/src/mame/drivers/jpms80.c
+++ b/src/mame/drivers/jpms80.c
@@ -17,7 +17,7 @@
System80 is based on the SRU platform, but with more outputs and finally a separate CPU and sound board setup to permit easy repair.
-
+
*/
diff --git a/src/mame/drivers/jpmsru.c b/src/mame/drivers/jpmsru.c
index 2ea3db32305..adb5c9b401b 100644
--- a/src/mame/drivers/jpmsru.c
+++ b/src/mame/drivers/jpmsru.c
@@ -10,9 +10,9 @@
the sound hardware seems to be a basic discrete circuit (complete
with tone pot), and the hardware uses the older TMS9980A as a CPU.
- TODO: Everything!, there are 10 different SRU subtypes, including
- one purely for export, though this is a layout change rather than
- anything significant.
+ TODO: Everything!, there are 10 different SRU subtypes, including
+ one purely for export, though this is a layout change rather than
+ anything significant.
**********************************************************************/
diff --git a/src/mame/drivers/m92.c b/src/mame/drivers/m92.c
index 829db958eb8..6c8cd6f872b 100644
--- a/src/mame/drivers/m92.c
+++ b/src/mame/drivers/m92.c
@@ -1978,7 +1978,7 @@ ROM_START( nbbatman2bl )
ROM_LOAD( "2.bin", 0x000000, 0x400000, CRC(bae2eb19) SHA1(609c805b23ceaf4cb02f4ad6192ab4dd50b89711) )
ROM_REGION( 0x200000, "irem", 0 )
- ROM_LOAD( "3.sou_rom", 0x000000, 0x100000, CRC(776ed65d) SHA1(0e3321c024a62fc48aa5541215af8af14c95ccc6) )
+ ROM_LOAD( "3.sou_rom", 0x000000, 0x100000, CRC(776ed65d) SHA1(0e3321c024a62fc48aa5541215af8af14c95ccc6) )
ROM_END
diff --git a/src/mame/drivers/mpu4hw.c b/src/mame/drivers/mpu4hw.c
index a3e1962db7e..6b3edd94731 100644
--- a/src/mame/drivers/mpu4hw.c
+++ b/src/mame/drivers/mpu4hw.c
@@ -2074,7 +2074,7 @@ how this is generated, and currently trial and error is the only sensible method
of all 00, is sometimes the correct answer, particularly in non-Barcrest use of the CHR chip, though when used normally,
there are again fixed call values.
-Apparently, just before the characteriser is checked bit 1 at 0x61DF is checked and if zero the characteriser
+Apparently, just before the characteriser is checked bit 1 at 0x61DF is checked and if zero the characteriser
check is bypassed. This may be something to look at for prototype ROMs and hacks.
*/
diff --git a/src/mame/drivers/namcos12.c b/src/mame/drivers/namcos12.c
index c52afc96de5..2bade98aacf 100644
--- a/src/mame/drivers/namcos12.c
+++ b/src/mame/drivers/namcos12.c
@@ -1293,7 +1293,7 @@ READ16_MEMBER(namcos12_state::system11gun_r)
break;
case 3:
- data = ioport("LIGHT0_Y")->read() + 1;
+ data = ioport("LIGHT0_Y")->read() + 1;
break;
case 4:
diff --git a/src/mame/drivers/nmk16.c b/src/mame/drivers/nmk16.c
index c1774a9275c..08daa9d7bb4 100644
--- a/src/mame/drivers/nmk16.c
+++ b/src/mame/drivers/nmk16.c
@@ -1127,7 +1127,7 @@ static ADDRESS_MAP_START( atombjt_map, AS_PROGRAM, 16, nmk16_state )
AM_RANGE(0x0C2010, 0x0C2011) AM_READ_PORT("IN0")
AM_RANGE(0x0C2012, 0x0C2013) AM_READ(atombjt_unkr_r)
AM_RANGE(0x0C2014, 0x0C2015) AM_READ(atombjt_unkr_r)
-
+
AM_RANGE(0x0C2016, 0x0C2017) AM_READ_PORT("DSW1")
AM_RANGE(0x0C2018, 0x0C2019) AM_READ_PORT("DSW2")
@@ -1137,9 +1137,9 @@ static ADDRESS_MAP_START( atombjt_map, AS_PROGRAM, 16, nmk16_state )
AM_RANGE(0x080002, 0x080003) AM_READ_PORT("IN1")
AM_RANGE(0x080014, 0x080015) AM_WRITE(nmk_flipscreen_w)
-// AM_RANGE(0x084000, 0x084001) AM_DEVREADWRITE8("oki1", okim6295_device, read, write, 0x00ff)
-// AM_RANGE(0x084010, 0x084011) AM_DEVREADWRITE8("oki2", okim6295_device, read, write, 0x00ff)
-// AM_RANGE(0x084020, 0x08402f) AM_DEVWRITE_LEGACY("nmk112", nmk112_okibank_lsb_w)
+// AM_RANGE(0x084000, 0x084001) AM_DEVREADWRITE8("oki1", okim6295_device, read, write, 0x00ff)
+// AM_RANGE(0x084010, 0x084011) AM_DEVREADWRITE8("oki2", okim6295_device, read, write, 0x00ff)
+// AM_RANGE(0x084020, 0x08402f) AM_DEVWRITE_LEGACY("nmk112", nmk112_okibank_lsb_w)
AM_RANGE(0x088000, 0x0887ff) AM_RAM_WRITE(paletteram_RRRRGGGGBBBBRGBx_word_w) AM_SHARE("paletteram")
AM_RANGE(0x094000, 0x094001) AM_WRITE(nmk_tilebank_w)
AM_RANGE(0x094002, 0x094003) AM_WRITENOP /* IRQ enable? */
@@ -4425,7 +4425,7 @@ static MACHINE_CONFIG_START( atombjt, nmk16_state )
MCFG_PALETTE_LENGTH(1024)
MCFG_VIDEO_START_OVERRIDE(nmk16_state,bjtwin)
-
+
// the bootleg just has a single OKI
/* sound hardware */
MCFG_SPEAKER_STANDARD_MONO("mono")
@@ -6377,7 +6377,7 @@ ROM_START( atombjt ) // based off bjtwina set
ROM_LOAD32_BYTE( "24.u42", 0x000002, 0x80000, CRC(4c30e15f) SHA1(f92185743594e4e4573ac3f6c0c091802a08d5bd) )
ROM_LOAD32_BYTE( "25.u39", 0x000001, 0x80000, CRC(ff1af60f) SHA1(4fe626c9d59ab9b945535b2f796f13adc900f1ed) )
ROM_LOAD32_BYTE( "26.u45", 0x000000, 0x80000, CRC(6cc4e817) SHA1(70f2ab50e228a029d3157c94fe0a79e7aad010bd) )
-
+
ROM_REGION( 0x100000, "gfx1", 0 )
ROM_COPY( "gfxtemp", 0x000000, 0x00000, 0x100000 )
@@ -6825,9 +6825,9 @@ ROM_END
DRIVER_INIT_MEMBER(nmk16_state,redfoxwp2a)
{
// todo collapse to one bitswap
- decryptcode( machine(),23, 22, 21, 20, 19, 18, 17, 16, /* */ 13,15, 14, /* */ 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 );
- decryptcode( machine(),23, 22, 21, 20, 19, 18, 17, 16, /* */14,15, /* */ 13,12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 );
- decryptcode( machine(),23, 22, 21, 20, 19, 18, /* */ 16, 17, /* */ 15,14,13,12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 );
+ decryptcode( machine(),23, 22, 21, 20, 19, 18, 17, 16, /* */ 13,15, 14, /* */ 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 );
+ decryptcode( machine(),23, 22, 21, 20, 19, 18, 17, 16, /* */14,15, /* */ 13,12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 );
+ decryptcode( machine(),23, 22, 21, 20, 19, 18, /* */ 16, 17, /* */ 15,14,13,12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 );
}
diff --git a/src/mame/drivers/pacman.c b/src/mame/drivers/pacman.c
index 813d6293426..746ed590b14 100644
--- a/src/mame/drivers/pacman.c
+++ b/src/mame/drivers/pacman.c
@@ -1517,8 +1517,8 @@ INPUT_PORTS_END
static INPUT_PORTS_START( pacmansp )
PORT_INCLUDE( pacman )
- PORT_MODIFY("DSW1")
- PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW:7")
+ PORT_MODIFY("DSW1")
+ PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW:7")
PORT_DIPSETTING( 0x40, DEF_STR( Normal ) )
PORT_DIPSETTING( 0x00, "Hard (Invalid)" ) // breaks the attract screen on this version
INPUT_PORTS_END
@@ -1526,7 +1526,7 @@ INPUT_PORTS_END
static INPUT_PORTS_START( pacuman )
PORT_INCLUDE( pacman )
- PORT_MODIFY("DSW1")
+ PORT_MODIFY("DSW1")
PORT_DIPNAME( 0x03, 0x00, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW:1,2")
PORT_DIPSETTING( 0x03, "2C/1C, 1C/1C" )
PORT_DIPSETTING( 0x01, "1C/2C, 1C/3C" )
@@ -3793,7 +3793,7 @@ There are 4 proms in the board, one of them is a color prom that is different fr
82s123 different from other sets
82s129-1.a9 == Ms. Pacman prom 82s126.1m
82s129-2.c9 == Ms. Pacman prom 82s126.3m
-82s129-3.d1 == Ms. Pacman prom 82s126.4a
+82s129-3.d1 == Ms. Pacman prom 82s126.4a
If you need more info about the board please write contact ricky2001 at AUMAP
*/
@@ -3816,7 +3816,7 @@ ROM_START( mspacmanbg )
ROM_REGION( 0x0200, "namco", 0 ) /* sound PROMs */
ROM_LOAD( "82s129-1.a9", 0x0000, 0x0100, CRC(a9cc86bf) SHA1(bbcec0570aeceb582ff8238a4bc8546a23430081) ) // == 82s126.1m
- ROM_LOAD( "82s129-2.c9", 0x0100, 0x0100, CRC(77245b66) SHA1(0c4d0bee858b97632411c440bea6948a74759746) ) /* timing - not used */ // == 82s126.3m
+ ROM_LOAD( "82s129-2.c9", 0x0100, 0x0100, CRC(77245b66) SHA1(0c4d0bee858b97632411c440bea6948a74759746) ) /* timing - not used */ // == 82s126.3m
ROM_END
@@ -6446,5 +6446,3 @@ GAME( 198?, cannonbp, 0, pacman, cannonbp, pacman_state, cannonbp, ROT
GAME( 1999, superabc, 0, superabc, superabc, pacman_state, superabc, ROT90, "hack (Two-Bit Score)", "Super ABC (Pac-Man multigame kit, Sep. 03 1999)", GAME_SUPPORTS_SAVE )
GAME( 1999, superabco,superabc, superabc, superabc, pacman_state, superabc, ROT90, "hack (Two-Bit Score)", "Super ABC (Pac-Man multigame kit, Mar. 08 1999)", GAME_SUPPORTS_SAVE )
-
-
diff --git a/src/mame/drivers/rallyx.c b/src/mame/drivers/rallyx.c
index 4784a4bbd3f..7c866899d86 100644
--- a/src/mame/drivers/rallyx.c
+++ b/src/mame/drivers/rallyx.c
@@ -368,7 +368,7 @@ static INPUT_PORTS_START( rallyx )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_START("P2")
- PORT_DIPNAME( 0x01, 0x01, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("P2:1")
+ PORT_DIPNAME( 0x01, 0x01, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("P2:1")
PORT_DIPSETTING( 0x01, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x00, DEF_STR( Cocktail ) )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
@@ -380,12 +380,12 @@ static INPUT_PORTS_START( rallyx )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_START("DSW")
- PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coinage ) ) PORT_DIPLOCATION("DSW:7,8")
+ PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coinage ) ) PORT_DIPLOCATION("DSW:7,8")
PORT_DIPSETTING( 0x40, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0xc0, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x80, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) )
- PORT_DIPNAME( 0x38, 0x08, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW:4,5,6")
+ PORT_DIPNAME( 0x38, 0x08, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW:4,5,6")
PORT_DIPSETTING( 0x10, "1 Car, Medium" )
PORT_DIPSETTING( 0x28, "1 Car, Hard" )
PORT_DIPSETTING( 0x00, "2 Cars, Easy" )
@@ -394,34 +394,34 @@ static INPUT_PORTS_START( rallyx )
PORT_DIPSETTING( 0x08, "3 Cars, Easy" )
PORT_DIPSETTING( 0x20, "3 Cars, Medium" )
PORT_DIPSETTING( 0x38, "3 Cars, Hard" )
- PORT_DIPNAME( 0x06, 0x02, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW:2,3")
- PORT_DIPSETTING( 0x02, "15000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
- PORT_DIPSETTING( 0x04, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
- PORT_DIPSETTING( 0x06, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
-
- PORT_DIPSETTING( 0x02, "10000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
- PORT_DIPSETTING( 0x04, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
- PORT_DIPSETTING( 0x06, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
-
- PORT_DIPSETTING( 0x02, "15000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
- PORT_DIPSETTING( 0x04, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
- PORT_DIPSETTING( 0x06, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
-
- PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
- PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
- PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
-
- PORT_DIPSETTING( 0x02, "10000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
- PORT_DIPSETTING( 0x04, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
- PORT_DIPSETTING( 0x06, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
-
- PORT_DIPSETTING( 0x02, "15000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
- PORT_DIPSETTING( 0x04, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
- PORT_DIPSETTING( 0x06, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
-
- PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x38)
- PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x38)
- PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x38)
+ PORT_DIPNAME( 0x06, 0x02, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW:2,3")
+ PORT_DIPSETTING( 0x02, "15000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x04, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x06, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
+
+ PORT_DIPSETTING( 0x02, "10000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
+ PORT_DIPSETTING( 0x04, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
+ PORT_DIPSETTING( 0x06, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
+
+ PORT_DIPSETTING( 0x02, "15000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
+ PORT_DIPSETTING( 0x04, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
+ PORT_DIPSETTING( 0x06, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
+
+ PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
+ PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
+ PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
+
+ PORT_DIPSETTING( 0x02, "10000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
+ PORT_DIPSETTING( 0x04, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
+ PORT_DIPSETTING( 0x06, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
+
+ PORT_DIPSETTING( 0x02, "15000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
+ PORT_DIPSETTING( 0x04, "30000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
+ PORT_DIPSETTING( 0x06, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
+
+ PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x38)
+ PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x38)
+ PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x38)
PORT_DIPSETTING( 0x00, DEF_STR( None ) )
PORT_SERVICE_DIPLOC( 0x01, 0x01, "DSW:1")
INPUT_PORTS_END
@@ -430,7 +430,7 @@ static INPUT_PORTS_START( nrallyx )
PORT_INCLUDE( rallyx )
PORT_MODIFY("DSW")
- PORT_DIPNAME( 0x38, 0x00, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW:4,5,6")
+ PORT_DIPNAME( 0x38, 0x00, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW:4,5,6")
PORT_DIPSETTING( 0x10, "1 Car, Medium" )
PORT_DIPSETTING( 0x28, "1 Car, Hard" )
PORT_DIPSETTING( 0x18, "2 Cars, Medium" )
@@ -440,34 +440,34 @@ static INPUT_PORTS_START( nrallyx )
PORT_DIPSETTING( 0x38, "3 Cars, Hard" )
PORT_DIPSETTING( 0x08, "4 Cars, Easy" )
- PORT_DIPNAME( 0x06, 0x02, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW:2,3")
- PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
- PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
- PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
+ PORT_DIPNAME( 0x06, 0x02, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW:2,3")
+ PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x00)
- PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x08)
- PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x08)
- PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x08)
+ PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x08)
+ PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x08)
+ PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x08)
- PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
- PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
- PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
+ PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
+ PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
+ PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x10)
- PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
- PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
- PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
+ PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
+ PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
+ PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x18)
- PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
- PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
- PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
+ PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
+ PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
+ PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x20)
- PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
- PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
- PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
+ PORT_DIPSETTING( 0x02, "20000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
+ PORT_DIPSETTING( 0x04, "40000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
+ PORT_DIPSETTING( 0x06, "60000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x28)
- PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
- PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
- PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
+ PORT_DIPSETTING( 0x02, "20000/80000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
+ PORT_DIPSETTING( 0x04, "20000/100000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
+ PORT_DIPSETTING( 0x06, "20000/120000" ) PORT_CONDITION("DSW", 0x38, EQUALS, 0x30)
INPUT_PORTS_END
@@ -497,7 +497,7 @@ static INPUT_PORTS_START( jungler )
PORT_BIT( 0x7f, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("DSW2") /* CPU board */
- PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2,3")
+ PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2,3")
PORT_DIPSETTING( 0x01, DEF_STR( 4C_1C ) )
PORT_DIPSETTING( 0x02, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x03, DEF_STR( 2C_1C ) )
@@ -506,7 +506,7 @@ static INPUT_PORTS_START( jungler )
PORT_DIPSETTING( 0x06, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x05, DEF_STR( 1C_3C ) )
PORT_DIPSETTING( 0x04, DEF_STR( 1C_4C ) )
- PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:4,5,6")
+ PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:4,5,6")
PORT_DIPSETTING( 0x08, DEF_STR( 4C_1C ) )
PORT_DIPSETTING( 0x10, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x18, DEF_STR( 2C_1C ) )
@@ -515,10 +515,10 @@ static INPUT_PORTS_START( jungler )
PORT_DIPSETTING( 0x30, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x28, DEF_STR( 1C_3C ) )
PORT_DIPSETTING( 0x20, DEF_STR( 1C_4C ) )
- PORT_DIPNAME( 0x40, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:7")
+ PORT_DIPNAME( 0x40, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:7")
PORT_DIPSETTING( 0x00, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x40, DEF_STR( Cocktail ) )
- PORT_DIPNAME( 0x80, 0x80, "Test (255 lives)" ) PORT_DIPLOCATION("DSW2:8")
+ PORT_DIPNAME( 0x80, 0x80, "Test (255 lives)" ) PORT_DIPLOCATION("DSW2:8")
PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
INPUT_PORTS_END
@@ -548,24 +548,24 @@ static INPUT_PORTS_START( locomotn )
PORT_START("DSW1") /* Sound board */
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
- PORT_DIPNAME( 0x30, 0x30, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:5,6")
+ PORT_DIPNAME( 0x30, 0x30, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:5,6")
PORT_DIPSETTING( 0x30, "3" )
PORT_DIPSETTING( 0x20, "4" )
PORT_DIPSETTING( 0x10, "5" )
PORT_DIPSETTING( 0x00, "255" )
- PORT_DIPNAME( 0x08, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW1:4")
+ PORT_DIPNAME( 0x08, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW1:4")
PORT_DIPSETTING( 0x00, DEF_STR( Upright ) )
- PORT_DIPSETTING( 0x08, DEF_STR( Cocktail ) )
+ PORT_DIPSETTING( 0x08, DEF_STR( Cocktail ) )
PORT_DIPUNUSED_DIPLOC( 0x04, 0x04, "DSW1:3")
- PORT_DIPNAME( 0x02, 0x02, "Intermissions" ) PORT_DIPLOCATION("DSW1:2")
+ PORT_DIPNAME( 0x02, 0x02, "Intermissions" ) PORT_DIPLOCATION("DSW1:2")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x02, DEF_STR( On ) )
- PORT_DIPNAME( 0x01, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DSW1:1")
+ PORT_DIPNAME( 0x01, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DSW1:1")
PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_START("DSW2") /* CPU board */
- PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2,3,4")
+ PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:1,2,3,4")
PORT_DIPSETTING( 0x04, DEF_STR( 4C_1C ) )
PORT_DIPSETTING( 0x0a, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x01, DEF_STR( 2C_1C ) )
@@ -582,7 +582,7 @@ static INPUT_PORTS_START( locomotn )
PORT_DIPSETTING( 0x05, DEF_STR( 1C_6C ) )
PORT_DIPSETTING( 0x09, DEF_STR( 1C_7C ) )
PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) )
- PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:5,6,7,8")
+ PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW2:5,6,7,8")
PORT_DIPSETTING( 0x40, DEF_STR( 4C_1C ) )
PORT_DIPSETTING( 0xa0, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x10, DEF_STR( 2C_1C ) )
@@ -606,33 +606,33 @@ INPUT_PORTS_END
static INPUT_PORTS_START( tactcian )
PORT_INCLUDE( locomotn )
- PORT_MODIFY("P1")
+ PORT_MODIFY("P1")
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 )
PORT_MODIFY("P2")
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
PORT_MODIFY("DSW1") /* Sound board */
- PORT_DIPNAME( 0x30, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:5,6")
+ PORT_DIPNAME( 0x30, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW1:5,6")
PORT_DIPSETTING( 0x30, "255" )
PORT_DIPSETTING( 0x20, "5" )
PORT_DIPSETTING( 0x10, "4" )
PORT_DIPSETTING( 0x00, "3" )
- PORT_DIPNAME( 0x06, 0x00, DEF_STR( Coinage ) ) PORT_DIPLOCATION("DSW1:2,3")
- PORT_DIPSETTING( 0x06, DEF_STR( 4C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
- PORT_DIPSETTING( 0x02, DEF_STR( 2C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
- PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
- PORT_DIPSETTING( 0x04, DEF_STR( 1C_2C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
- PORT_DIPSETTING( 0x02, DEF_STR( 2C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
- PORT_DIPSETTING( 0x04, "A 2C/1C B 1C/3C" ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
- PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
- PORT_DIPSETTING( 0x06, "A 1C/1C B 1C/6C" ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
- PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW1:1")
+ PORT_DIPNAME( 0x06, 0x00, DEF_STR( Coinage ) ) PORT_DIPLOCATION("DSW1:2,3")
+ PORT_DIPSETTING( 0x06, DEF_STR( 4C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x02, DEF_STR( 2C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x04, DEF_STR( 1C_2C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x02, DEF_STR( 2C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
+ PORT_DIPSETTING( 0x04, "A 2C/1C B 1C/3C" ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
+ PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
+ PORT_DIPSETTING( 0x06, "A 1C/1C B 1C/6C" ) PORT_CONDITION("DSW2", 0x01, EQUALS, 0x01)
+ PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("DSW1:1")
PORT_DIPSETTING( 0x00, "10k, 80k then every 100k" )
PORT_DIPSETTING( 0x01, "20k, 80k then every 100k" )
PORT_MODIFY("DSW2") /* CPU board */
- PORT_DIPNAME( 0x01, 0x00, "Coin Mode" ) PORT_DIPLOCATION("DSW2:1")
+ PORT_DIPNAME( 0x01, 0x00, "Coin Mode" ) PORT_DIPLOCATION("DSW2:1")
PORT_DIPSETTING( 0x00, "Mode 1" )
PORT_DIPSETTING( 0x01, "Mode 2" )
PORT_DIPUNUSED_DIPLOC( 0x02, 0x00, "DSW2:2")
@@ -668,13 +668,13 @@ static INPUT_PORTS_START( commsega )
PORT_START("DSW1") /* (sound board) */
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
- PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_DIPLOCATION("DSW1:7")
+ PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_DIPLOCATION("DSW1:7")
PORT_DIPUNUSED_DIPLOC( 0x20, 0x20, "DSW1:6")
PORT_DIPUNUSED_DIPLOC( 0x10, 0x10, "DSW1:5")
- PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) PORT_DIPLOCATION("DSW1:4") // "Infinite Lives" - See notes
+ PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) PORT_DIPLOCATION("DSW1:4") // "Infinite Lives" - See notes
PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW1:1,2,3")
+ PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW1:1,2,3")
PORT_DIPSETTING( 0x04, DEF_STR( 4C_1C ) )
PORT_DIPSETTING( 0x05, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x06, DEF_STR( 2C_1C ) )
@@ -685,12 +685,12 @@ static INPUT_PORTS_START( commsega )
PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) )
PORT_START("DSW2") /* (CPU board) */
- PORT_DIPNAME( 0x03, 0x03, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW2:1,2")
+ PORT_DIPNAME( 0x03, 0x03, DEF_STR( Lives ) ) PORT_DIPLOCATION("DSW2:1,2")
PORT_DIPSETTING( 0x03, "3" )
PORT_DIPSETTING( 0x02, "4" )
PORT_DIPSETTING( 0x01, "5" )
PORT_DIPSETTING( 0x00, "6" )
- PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:3,4,5")
+ PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW2:3,4,5")
PORT_DIPSETTING( 0x10, DEF_STR( 4C_1C ) ) // Bonus Life : 50000 points
PORT_DIPSETTING( 0x14, DEF_STR( 3C_1C ) ) // Bonus Life : 50000 points
PORT_DIPSETTING( 0x18, DEF_STR( 2C_1C ) ) // Bonus Life : 30000 points
@@ -703,7 +703,7 @@ static INPUT_PORTS_START( commsega )
PORT_DIPNAME( 0x40, 0x40, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("DSW2:7") // Check code at 0x1fc5
PORT_DIPSETTING( 0x40, DEF_STR( Easy ) ) // 16 flying enemies to kill
PORT_DIPSETTING( 0x00, DEF_STR( Hard ) ) // 24 flying enemies to kill
- PORT_DIPNAME( 0x80, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:8")
+ PORT_DIPNAME( 0x80, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:8")
PORT_DIPSETTING( 0x00, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x80, DEF_STR( Cocktail ) )
INPUT_PORTS_END
diff --git a/src/mame/drivers/seabattl.c b/src/mame/drivers/seabattl.c
index 2d43c0204f3..fc17f4954eb 100644
--- a/src/mame/drivers/seabattl.c
+++ b/src/mame/drivers/seabattl.c
@@ -11,7 +11,7 @@ sea b b_1 *.prg are 2650 progamm
sea b blu.prg is blue data?
sea b red.prg is red data?
-sea b green.prg is green data? for video?
+sea b green.prg is green data? for video?
sea b wawe.prg is sea wave data?
@@ -21,56 +21,56 @@ sea b screen.prg ???
the sound board should be fully discrete.
-DS0 1 2 3
-PLAY TIME ON ON ON free game
- ON OFF ON 75 seconds
- OFF OFF ON 90 seconds
- OFF ON ON 105 seconds
-
-SHIP NUMBER ON ON OFF free game
- ON OFF OFF 3 ships
- OFF OFF OFF 4 ships
- OFF ON OFF 5 ships
- I don't forget anything, this is a copy of the manual
- DS0-3 seem to select from time based games to ships based game.
-
-
-
-DS0 4 5 6
-COIN SLOT 2 ON ON ON 2 coin 1 play
- ON OFF ON 1 coin 1 play
- ON ON OFF 1 coin 2 plays
- ON OFF OFF 1 coin 3 plays
- OFF ON ON 1 coin 4 plays
- OFF OFF ON 1 coin 5 plays
- OFF ON OFF 1 coin 6 plays
- OFF OFF OFF 1 coin 7 plays
-
-
-DS0 7 8 DS1-1
-COIN SLOT 1 ON ON ON 2 coin 1 play
- ON OFF ON 1 coin 1 play
- ON ON OFF 1 coin 2 plays
- ON OFF OFF 1 coin 3 plays
- OFF ON ON 1 coin 4 plays
- OFF OFF ON 1 coin 5 plays
- OFF ON OFF 1 coin 6 plays
- OFF OFF OFF 1 coin 7 plays
-
-DS1 2
-SHIP SPEED ON fast
- OFF slow
-
-
-DS1 3 4
-EXTEND PLAY OFF OFF no extended
- ON OFF 2000 points
- OFF ON 3000 points
- ON ON 4000 points
-
-DS1 5
-GRID ON game
- OFF grid
+DS0 1 2 3
+PLAY TIME ON ON ON free game
+ ON OFF ON 75 seconds
+ OFF OFF ON 90 seconds
+ OFF ON ON 105 seconds
+
+SHIP NUMBER ON ON OFF free game
+ ON OFF OFF 3 ships
+ OFF OFF OFF 4 ships
+ OFF ON OFF 5 ships
+ I don't forget anything, this is a copy of the manual
+ DS0-3 seem to select from time based games to ships based game.
+
+
+
+DS0 4 5 6
+COIN SLOT 2 ON ON ON 2 coin 1 play
+ ON OFF ON 1 coin 1 play
+ ON ON OFF 1 coin 2 plays
+ ON OFF OFF 1 coin 3 plays
+ OFF ON ON 1 coin 4 plays
+ OFF OFF ON 1 coin 5 plays
+ OFF ON OFF 1 coin 6 plays
+ OFF OFF OFF 1 coin 7 plays
+
+
+DS0 7 8 DS1-1
+COIN SLOT 1 ON ON ON 2 coin 1 play
+ ON OFF ON 1 coin 1 play
+ ON ON OFF 1 coin 2 plays
+ ON OFF OFF 1 coin 3 plays
+ OFF ON ON 1 coin 4 plays
+ OFF OFF ON 1 coin 5 plays
+ OFF ON OFF 1 coin 6 plays
+ OFF OFF OFF 1 coin 7 plays
+
+DS1 2
+SHIP SPEED ON fast
+ OFF slow
+
+
+DS1 3 4
+EXTEND PLAY OFF OFF no extended
+ ON OFF 2000 points
+ OFF ON 3000 points
+ ON ON 4000 points
+
+DS1 5
+GRID ON game
+ OFF grid
DS1 6-7-8 not used
@@ -106,7 +106,6 @@ UINT32 seabattl_state::screen_update_seabattl(screen_device &screen, bitmap_ind1
void seabattl_state::video_start()
{
-
}
static ADDRESS_MAP_START( seabattl_map, AS_PROGRAM, 8, seabattl_state )
@@ -121,12 +120,10 @@ INPUT_PORTS_END
void seabattl_state::machine_start()
{
-
}
void seabattl_state::machine_reset()
{
-
}
static const gfx_layout tiles32x16x3_layout =
@@ -164,8 +161,8 @@ static MACHINE_CONFIG_START( seabattl, seabattl_state )
/* basic machine hardware */
MCFG_CPU_ADD("maincpu", S2650, 14318180/4) // ???
MCFG_CPU_PROGRAM_MAP(seabattl_map)
-// MCFG_CPU_IO_MAP(seabattl_io_map)
-// MCFG_CPU_VBLANK_INT_DRIVER("screen", seabattl_state, seabattl_interrupt)
+// MCFG_CPU_IO_MAP(seabattl_io_map)
+// MCFG_CPU_VBLANK_INT_DRIVER("screen", seabattl_state, seabattl_interrupt)
MCFG_PALETTE_LENGTH(256)
diff --git a/src/mame/drivers/snookr10.c b/src/mame/drivers/snookr10.c
index 10b28714281..70e17160c04 100644
--- a/src/mame/drivers/snookr10.c
+++ b/src/mame/drivers/snookr10.c
@@ -125,7 +125,7 @@
- Tile matrix and color data (video & color RAM) are totally encrypted/scrambled.
You can see the following table, where 'Normal tile #' is the tile number called
- to be drawn, and 'Scrambled tile #' is the phisical tile position in the matrix:
+ to be drawn, and 'Scrambled tile #' is the phisical tile position in the matrix:
Normal | Scrambled
tile # | tile #
@@ -262,7 +262,7 @@
- Tile matrix and color data (video & color RAM) are totally encrypted/scrambled.
You can see the following table, where 'Normal tile #' is the tile number called
- to be drawn, and 'Scrambled tile #' is the phisical tile position in the matrix:
+ to be drawn, and 'Scrambled tile #' is the phisical tile position in the matrix:
Normal | Scrambled
tile # | tile #
@@ -405,7 +405,7 @@
||||+---------> 7 |
|||+----------> 1 |
||+-----------> 5 |
- |+------------> A /
+ |+------------> A /
+-------------> 0 -
@@ -492,7 +492,7 @@
$0000 - $07FF NVRAM (battery backed 6116) ;R/W, all registers and settings.
$1000 - $1000 Output Port 0 ; W, lamps & counters.
$1001 - $1001 Output Port 1 ; W, lamps.
- $2000 - $2008 Special Input ;R , special ports meant for data channels...
+ $2000 - $2008 Special Input ;R , special ports meant for data channels...
$3000 - $3000 Input Port 0 ;R
$3001 - $3001 Input Port 1 ;R
$3002 - $3002 Input Port 2 ;R
@@ -511,26 +511,26 @@
[2013/05/12]
- Crystals Colours:
+ Crystals Colours:
- Decrypted the tile matrix / video RAM.
- - Wrote proper memory map and inputs from the scratch.
- - Bypassed the program data channels protection.
+ - Wrote proper memory map and inputs from the scratch.
+ - Bypassed the program data channels protection.
- Decrypted the colors / color RAM.
- Added button-lamps support.
- Created a default NVRAM.
- Promoted to working state.
- - Added technical and encryption notes...
+ - Added technical and encryption notes...
Snooker 10:
- - Fixed NVRAM size.
+ - Fixed NVRAM size.
- Added default NVRAM.
Apple 10:
- - Fixed NVRAM size.
+ - Fixed NVRAM size.
- Added default NVRAM.
Ten Balls:
- - Fixed NVRAM size.
+ - Fixed NVRAM size.
- Added default NVRAM.
@@ -750,9 +750,9 @@ READ8_MEMBER(snookr10_state::port2000_8_r)
{
/*
Ports 2000-2008 expect data, otherwise the program trigger
- a sort of service-text mode, sets 300000 points and starts
- to decrease the amount one by one, triggering a sound each
- time the amount is decremented.
+ a sort of service-text mode, sets 300000 points and starts
+ to decrease the amount one by one, triggering a sound each
+ time the amount is decremented.
*/
return 0xff;
}
@@ -762,7 +762,7 @@ READ8_MEMBER(snookr10_state::port2000_8_r)
*************************/
static ADDRESS_MAP_START( snookr10_map, AS_PROGRAM, 8, snookr10_state )
- AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram") /* battery backed 6116 */
+ AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram") /* battery backed 6116 */
AM_RANGE(0x1000, 0x1000) AM_DEVREADWRITE("oki", okim6295_device, read, write)
AM_RANGE(0x3000, 0x3000) AM_READ_PORT("IN0") /* IN0 */
AM_RANGE(0x3001, 0x3001) AM_READ_PORT("IN1") /* IN1 */
@@ -777,7 +777,7 @@ static ADDRESS_MAP_START( snookr10_map, AS_PROGRAM, 8, snookr10_state )
ADDRESS_MAP_END
static ADDRESS_MAP_START( tenballs_map, AS_PROGRAM, 8, snookr10_state )
- AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram") /* battery backed 6116 */
+ AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram") /* battery backed 6116 */
AM_RANGE(0x1000, 0x1000) AM_DEVREADWRITE("oki", okim6295_device, read, write)
AM_RANGE(0x4000, 0x4000) AM_READ_PORT("IN0") /* IN0 */
AM_RANGE(0x4001, 0x4001) AM_READ_PORT("IN1") /* IN1 */
@@ -791,10 +791,10 @@ static ADDRESS_MAP_START( tenballs_map, AS_PROGRAM, 8, snookr10_state )
ADDRESS_MAP_END
static ADDRESS_MAP_START( crystalc_map, AS_PROGRAM, 8, snookr10_state )
- AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram") /* battery backed 6116 */
+ AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram") /* battery backed 6116 */
AM_RANGE(0x1000, 0x1000) AM_WRITE(output_port_0_w) /* OUT0 */
AM_RANGE(0x1001, 0x1001) AM_WRITE(output_port_1_w) /* OUT1 */
- AM_RANGE(0x2000, 0x2008) AM_READ(port2000_8_r) /* unknown... protection or data channels? */
+ AM_RANGE(0x2000, 0x2008) AM_READ(port2000_8_r) /* unknown... protection or data channels? */
AM_RANGE(0x3000, 0x3000) AM_READ_PORT("IN0") /* IN0 */
AM_RANGE(0x3001, 0x3001) AM_READ_PORT("IN1") /* IN1 */
AM_RANGE(0x3002, 0x3002) AM_READ_PORT("IN2") /* IN2 */
@@ -963,32 +963,32 @@ static INPUT_PORTS_START( crystalc )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
- PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) // SG vs real value in paytable.
+ PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) // SG vs real value in paytable.
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("SW1")
- PORT_DIPNAME( 0x03, 0x00, "Pool Value" ) PORT_DIPLOCATION("SW1:7,8")
+ PORT_DIPNAME( 0x03, 0x00, "Pool Value" ) PORT_DIPLOCATION("SW1:7,8")
PORT_DIPSETTING( 0x03, "100" )
PORT_DIPSETTING( 0x02, "200" )
PORT_DIPSETTING( 0x01, "500" )
PORT_DIPSETTING( 0x00, "1000" )
- PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:6")
+ PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:6")
PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:5")
+ PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:5")
PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:4")
+ PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:4")
PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x60, 0x60, "Payment Type" ) PORT_DIPLOCATION("SW1:3,2")
+ PORT_DIPNAME( 0x60, 0x60, "Payment Type" ) PORT_DIPLOCATION("SW1:3,2")
PORT_DIPSETTING( 0x00, "Ticket + Coins" )
PORT_DIPSETTING( 0x20, "Ticket only" )
PORT_DIPSETTING( 0x40, "Coins only" )
PORT_DIPSETTING( 0x60, "Ticket + Coins" )
- PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:1")
+ PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:1")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x80, DEF_STR( On ) )
INPUT_PORTS_END
diff --git a/src/mame/drivers/stuntair.c b/src/mame/drivers/stuntair.c
index 2d70869ecff..3d6f54521ce 100644
--- a/src/mame/drivers/stuntair.c
+++ b/src/mame/drivers/stuntair.c
@@ -47,7 +47,7 @@ Bproms are 82s123,82s129
Dip switches (by direct test,no manuals present):
-DIP A-
-SW 1 2 3 5 6 7 8
+SW 1 2 3 5 6 7 8
unknown
SW 4
OFF infinite lives (test)
@@ -74,7 +74,7 @@ SW 7 8
OFF ON 3 lives
ON ON 2 lives
Note: no table-upright mode sw,upright fixed.No picture flip sw too
-
+
Eprom dump,hw and dip info by tirino73
Bprom dump by f205v
@@ -139,7 +139,7 @@ public:
if (data&~0x01) printf("stuntair_f001_w %02x\n", data);
}
-
+
DECLARE_WRITE8_MEMBER(stuntair_spritebank0_w)
{
m_spritebank0 = data&0x01;
@@ -166,7 +166,7 @@ public:
m_audiocpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
}
-
+
INTERRUPT_GEN_MEMBER(stuntair_irq);
@@ -179,7 +179,7 @@ public:
{
return m_soundlatch;
}
-
+
DECLARE_READ8_MEMBER(ay8910_in1_r)
{
printf("ay8910_in1_r\n");
@@ -207,13 +207,13 @@ static ADDRESS_MAP_START( stuntair_map, AS_PROGRAM, 8, stuntair_state )
AM_RANGE(0xf000, 0xf000) AM_READ_PORT("IN2")
AM_RANGE(0xf001, 0xf001) AM_WRITE(stuntair_f001_w) // might be nmi enable
AM_RANGE(0xf002, 0xf002) AM_READ_PORT("IN3")
- AM_RANGE(0xf003, 0xf003) AM_READ_PORT("IN4") AM_WRITE(stuntair_spritebank1_w)
-// AM_RANGE(0xf004, 0xf004) AM_WRITENOP
- AM_RANGE(0xf005, 0xf005) AM_WRITE(stuntair_spritebank0_w)
-// AM_RANGE(0xf006, 0xf006) AM_WRITENOP
-// AM_RANGE(0xf007, 0xf007) AM_WRITENOP
+ AM_RANGE(0xf003, 0xf003) AM_READ_PORT("IN4") AM_WRITE(stuntair_spritebank1_w)
+// AM_RANGE(0xf004, 0xf004) AM_WRITENOP
+ AM_RANGE(0xf005, 0xf005) AM_WRITE(stuntair_spritebank0_w)
+// AM_RANGE(0xf006, 0xf006) AM_WRITENOP
+// AM_RANGE(0xf007, 0xf007) AM_WRITENOP
+
-
AM_RANGE(0xf800, 0xfbff) AM_RAM_WRITE(stuntair_fgram_w) AM_SHARE("fgram")
@@ -277,13 +277,13 @@ static INPUT_PORTS_START( stuntair )
PORT_DIPNAME( 0x02, 0x02, "DSWA:6" )
PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x80, 0x80, "DSWA:7" )
+ PORT_DIPNAME( 0x80, 0x80, "DSWA:7" )
PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x01, 0x01, "DSWA:8" )
PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
-
+
PORT_START("IN2")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 )
@@ -293,10 +293,10 @@ static INPUT_PORTS_START( stuntair )
PORT_DIPNAME( 0x08, 0x08, "IN2:3" )
PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
- PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
- PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
- PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
+ PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
+ PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
+ PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
+ PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
PORT_START("IN3")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
@@ -401,7 +401,7 @@ TILE_GET_INFO_MEMBER(stuntair_state::get_stuntair_fg_tile_info)
int opaque = tileno & 0x80;
// where does the FG palette come from? it's a 1bpp layer..
-
+
SET_TILE_INFO_MEMBER(0, tileno&0x7f, 0, opaque?TILE_FORCE_LAYER0 : TILE_FORCE_LAYER1);
}
@@ -468,11 +468,11 @@ UINT32 stuntair_state::screen_update_stuntair(screen_device &screen, bitmap_ind1
int colour = m_sprram[(i*16)+4] & 0x7;
int tile = m_sprram[(i*16)+1] & 0x3f;
int flipy = (m_sprram[(i*16)+1] & 0x80)>>7; // used
-// int flipx = (m_sprram[(i*16)+1] & 0x40)>>6; // guessed , wrong
+// int flipx = (m_sprram[(i*16)+1] & 0x40)>>6; // guessed , wrong
int flipx = 0;
-
+
if (m_spritebank1) tile |= 0x40;
- if (m_spritebank0) tile |= 0x80;
+ if (m_spritebank0) tile |= 0x80;
y = 240 - y;
diff --git a/src/mame/drivers/su2000.c b/src/mame/drivers/su2000.c
index c420156b73f..aa199def0a3 100644
--- a/src/mame/drivers/su2000.c
+++ b/src/mame/drivers/su2000.c
@@ -152,16 +152,16 @@ READ8_MEMBER(su2000_state::get_slave_ack)
//static const struct pic8259_interface su2000_pic8259_1_config =
//{
-// DEVCB_DRIVER_LINE_MEMBER(su2000_state,su2000_pic8259_1_set_int_line),
-// DEVCB_LINE_VCC,
-// DEVCB_DRIVER_MEMBER(su2000_state,get_slave_ack)
+// DEVCB_DRIVER_LINE_MEMBER(su2000_state,su2000_pic8259_1_set_int_line),
+// DEVCB_LINE_VCC,
+// DEVCB_DRIVER_MEMBER(su2000_state,get_slave_ack)
//};
//
//static const struct pic8259_interface su2000_pic8259_2_config =
//{
-// DEVCB_DEVICE_LINE_MEMBER("pic8259_1", pic8259_device, ir2_w),
-// DEVCB_LINE_GND,
-// DEVCB_NULL
+// DEVCB_DEVICE_LINE_MEMBER("pic8259_1", pic8259_device, ir2_w),
+// DEVCB_LINE_GND,
+// DEVCB_NULL
//};
diff --git a/src/mame/drivers/system16.c b/src/mame/drivers/system16.c
index 5878d960453..390057e8f40 100644
--- a/src/mame/drivers/system16.c
+++ b/src/mame/drivers/system16.c
@@ -2822,7 +2822,7 @@ Xtal 20Mzh
Audio
Z80
-2 ym2203
+2 ym2203
2 y3014B
Rom 1 and 2 are snd
@@ -2859,7 +2859,7 @@ ROM_START( altbeastbl )
ROM_LOAD16_BYTE( "24.bin", 0x0a0001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) ) // == epr-11718.a2
ROM_LOAD16_BYTE( "26.bin", 0x0a0000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) ) // == epr-11734.b11
ROM_LOAD16_BYTE( "13.bin", 0x0c0001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) ) // == epr-11719.a3
- ROM_LOAD16_BYTE( "14.bin", 0x0c0000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) ) // == epr-11735.b12
+ ROM_LOAD16_BYTE( "14.bin", 0x0c0000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) ) // == epr-11735.b12
ROM_REGION( 0x50000, "soundcpu", 0 ) // sound CPU
ROM_LOAD( "1.bin", 0x00000, 0x10000, CRC(67e09da3) SHA1(1c57048b428027fb8fae531363930ac5fed961fe) )
@@ -3514,7 +3514,7 @@ GAME( 1989, goldnaxeb1, goldnaxe, goldnaxeb1, goldnaxe, segas1x_bootleg_state
GAME( 1989, goldnaxeb2, goldnaxe, goldnaxeb2, goldnaxe, segas1x_bootleg_state, goldnaxeb2, ROT0, "bootleg", "Golden Axe (bootleg)", GAME_NOT_WORKING|GAME_NO_SOUND )
GAME( 1989, tturfbl, tturf, tturfbl, tturf, segas1x_bootleg_state, tturfbl, ROT0, "bootleg (Datsu)", "Tough Turf (Datsu bootleg)", GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
GAME( 1989, dduxbl, ddux, dduxbl, ddux, segas1x_bootleg_state, dduxbl, ROT0, "bootleg (Datsu)", "Dynamite Dux (Datsu bootleg)", GAME_NOT_WORKING )
-GAME( 1988, altbeastbl, altbeast, tetrisbl, tetris, segas1x_bootleg_state, dduxbl, ROT0, "bootleg (Datsu)", "Altered Beast (Datsu bootleg)", GAME_NOT_WORKING )
+GAME( 1988, altbeastbl, altbeast, tetrisbl, tetris, segas1x_bootleg_state, dduxbl, ROT0, "bootleg (Datsu)", "Altered Beast (Datsu bootleg)", GAME_NOT_WORKING )
GAME( 1989, eswatbl, eswat, eswatbl, eswat, segas1x_bootleg_state, eswatbl, ROT0, "bootleg", "E-Swat - Cyber Police (bootleg)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND )
GAME( 1989, fpointbl, fpoint, fpointbl, fpointbl, segas1x_bootleg_state, fpointbl, ROT0, "bootleg (Datsu)", "Flash Point (World, bootleg)", GAME_NOT_WORKING )
GAME( 1989, fpointbj, fpoint, fpointbl, fpointbl, segas1x_bootleg_state, fpointbl, ROT0, "bootleg (Datsu)", "Flash Point (Japan, bootleg)", GAME_NOT_WORKING )
diff --git a/src/mame/drivers/taitogn.c b/src/mame/drivers/taitogn.c
index 5cbe31d99ab..cd9412e4d01 100644
--- a/src/mame/drivers/taitogn.c
+++ b/src/mame/drivers/taitogn.c
@@ -719,9 +719,9 @@ MACHINE_RESET_MEMBER(taitogn_state,coh3002t)
}
static ADDRESS_MAP_START( taitogn_map, AS_PROGRAM, 32, taitogn_state )
-// AM_RANGE(0x1f000000, 0x1f1fffff) AM_DEVREADWRITE16("sndflash0", intelfsh16_device, read, write, 0xffffffff)
-// AM_RANGE(0x1f200000, 0x1f3fffff) AM_DEVREADWRITE16("sndflash1", intelfsh16_device, read, write, 0xffffffff)
-// AM_RANGE(0x1f400000, 0x1f5fffff) AM_DEVREADWRITE16("sndflash2", intelfsh16_device, read, write, 0xffffffff)
+// AM_RANGE(0x1f000000, 0x1f1fffff) AM_DEVREADWRITE16("sndflash0", intelfsh16_device, read, write, 0xffffffff)
+// AM_RANGE(0x1f200000, 0x1f3fffff) AM_DEVREADWRITE16("sndflash1", intelfsh16_device, read, write, 0xffffffff)
+// AM_RANGE(0x1f400000, 0x1f5fffff) AM_DEVREADWRITE16("sndflash2", intelfsh16_device, read, write, 0xffffffff)
AM_RANGE(0x1fa00000, 0x1fa00003) AM_READ_PORT("P1")
AM_RANGE(0x1fa00100, 0x1fa00103) AM_READ_PORT("P2")
AM_RANGE(0x1fa00200, 0x1fa00203) AM_READ_PORT("SERVICE")
diff --git a/src/mame/drivers/travrusa.c b/src/mame/drivers/travrusa.c
index e019c20bc26..e78d5430afd 100644
--- a/src/mame/drivers/travrusa.c
+++ b/src/mame/drivers/travrusa.c
@@ -102,73 +102,73 @@ static INPUT_PORTS_START( travrusa )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
PORT_START("DSW1")
- PORT_DIPNAME( 0x03, 0x03, "Fuel Reduced on Collision" ) PORT_DIPLOCATION("DSW1:1,2")
+ PORT_DIPNAME( 0x03, 0x03, "Fuel Reduced on Collision" ) PORT_DIPLOCATION("DSW1:1,2")
PORT_DIPSETTING( 0x03, DEF_STR( Low ) )
PORT_DIPSETTING( 0x02, "Med" )
PORT_DIPSETTING( 0x01, "Hi" )
PORT_DIPSETTING( 0x00, "Max" )
- PORT_DIPNAME( 0x04, 0x04, "Fuel Consumption" ) PORT_DIPLOCATION("DSW1:3")
+ PORT_DIPNAME( 0x04, 0x04, "Fuel Consumption" ) PORT_DIPLOCATION("DSW1:3")
PORT_DIPSETTING( 0x04, DEF_STR( Low ) )
PORT_DIPSETTING( 0x00, "Hi" )
- PORT_DIPNAME( 0x08, 0x00, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("DSW1:4")
+ PORT_DIPNAME( 0x08, 0x00, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("DSW1:4")
PORT_DIPSETTING( 0x08, DEF_STR( No ) )
PORT_DIPSETTING( 0x00, DEF_STR( Yes ) )
- PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coinage ) ) PORT_DIPLOCATION("DSW1:5,6,7,8")
- PORT_DIPSETTING( 0x80, "Not Used" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x90, "Not Used" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0xa0, DEF_STR( 6C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0xb0, DEF_STR( 5C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0xc0, DEF_STR( 4C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0xd0, DEF_STR( 3C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0xe0, DEF_STR( 2C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0xf0, DEF_STR( 1C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x70, DEF_STR( 1C_2C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x60, DEF_STR( 1C_3C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x50, DEF_STR( 1C_4C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x40, DEF_STR( 1C_5C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x30, DEF_STR( 1C_6C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x20, DEF_STR( 1C_7C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x10, "Not Used" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
- PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
-
- PORT_DIPSETTING( 0x80, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x90, "A 3C_1C / B 1C_3C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0xa0, "A 2C_1C / B 1C_3C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0xb0, "A 1C_1C / B 1C_3C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0xc0, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0xd0, "A 3C_1C / B 1C_2C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0xe0, "A 2C_1C / B 1C_2C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0xf0, "A 1C_1C / B 1C_2C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x70, "A 1C_1C / B 1C_5C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x60, "A 2C_1C / B 1C_5C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x50, "A 3C_1C / B 1C_5C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x40, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x30, "A 1C_1C / B 1C_6C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x20, "A 2C_1C / B 1C_6C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x10, "A 3C_1C / B 1C_6C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
- PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coinage ) ) PORT_DIPLOCATION("DSW1:5,6,7,8")
+ PORT_DIPSETTING( 0x80, "Not Used" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x90, "Not Used" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0xa0, DEF_STR( 6C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0xb0, DEF_STR( 5C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0xc0, DEF_STR( 4C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0xd0, DEF_STR( 3C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0xe0, DEF_STR( 2C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0xf0, DEF_STR( 1C_1C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x70, DEF_STR( 1C_2C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x60, DEF_STR( 1C_3C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x50, DEF_STR( 1C_4C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x40, DEF_STR( 1C_5C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x30, DEF_STR( 1C_6C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x20, DEF_STR( 1C_7C ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x10, "Not Used" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+ PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x04)
+
+ PORT_DIPSETTING( 0x80, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x90, "A 3C_1C / B 1C_3C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0xa0, "A 2C_1C / B 1C_3C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0xb0, "A 1C_1C / B 1C_3C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0xc0, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0xd0, "A 3C_1C / B 1C_2C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0xe0, "A 2C_1C / B 1C_2C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0xf0, "A 1C_1C / B 1C_2C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x70, "A 1C_1C / B 1C_5C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x60, "A 2C_1C / B 1C_5C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x50, "A 3C_1C / B 1C_5C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x40, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x30, "A 1C_1C / B 1C_6C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x20, "A 2C_1C / B 1C_6C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x10, "A 3C_1C / B 1C_6C" ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
+ PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) ) PORT_CONDITION("DSW2", 0x04, EQUALS, 0x00)
PORT_START("DSW2")
- PORT_DIPNAME( 0x01, 0x01, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:1")
+ PORT_DIPNAME( 0x01, 0x01, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:1")
PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x02, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:2")
+ PORT_DIPNAME( 0x02, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:2")
PORT_DIPSETTING( 0x00, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x02, DEF_STR( Cocktail ) )
- PORT_DIPNAME( 0x04, 0x04, "Coin Mode" ) PORT_DIPLOCATION("DSW2:3")
+ PORT_DIPNAME( 0x04, 0x04, "Coin Mode" ) PORT_DIPLOCATION("DSW2:3")
PORT_DIPSETTING( 0x04, "Mode 1" )
PORT_DIPSETTING( 0x00, "Mode 2" )
- PORT_DIPNAME( 0x08, 0x08, "Speed Type" ) PORT_DIPLOCATION("DSW2:4")
+ PORT_DIPNAME( 0x08, 0x08, "Speed Type" ) PORT_DIPLOCATION("DSW2:4")
PORT_DIPSETTING( 0x08, "M/H" ) //mph ?
PORT_DIPSETTING( 0x00, "Km/H" )
/* In stop mode, press 2 to stop and 1 to restart */
- PORT_DIPNAME( 0x10, 0x10, "Stop Mode (Cheat)") PORT_DIPLOCATION("DSW2:5")
+ PORT_DIPNAME( 0x10, 0x10, "Stop Mode (Cheat)") PORT_DIPLOCATION("DSW2:5")
PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x20, 0x20, "Title" ) PORT_DIPLOCATION("DSW2:6")
+ PORT_DIPNAME( 0x20, 0x20, "Title" ) PORT_DIPLOCATION("DSW2:6")
PORT_DIPSETTING( 0x20, "Traverse USA" )
PORT_DIPSETTING( 0x00, "Zippy Race" )
- PORT_DIPNAME( 0x40, 0x40, "Invulnerability (Cheat)") PORT_DIPLOCATION("DSW2:7")
+ PORT_DIPNAME( 0x40, 0x40, "Invulnerability (Cheat)") PORT_DIPLOCATION("DSW2:7")
PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_SERVICE_DIPLOC( 0x80, 0x80, "DSW2:8")
@@ -208,7 +208,7 @@ static INPUT_PORTS_START( shtrider )
PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("DSW1")
- PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW1:1,2,3")
+ PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("DSW1:1,2,3")
PORT_DIPSETTING( 0x00, DEF_STR( 5C_1C ) )
PORT_DIPSETTING( 0x04, DEF_STR( 4C_1C ) )
PORT_DIPSETTING( 0x02, DEF_STR( 3C_1C ) )
@@ -217,7 +217,7 @@ static INPUT_PORTS_START( shtrider )
PORT_DIPSETTING( 0x03, DEF_STR( 1C_2C ) )
PORT_DIPSETTING( 0x05, DEF_STR( 1C_3C ) )
PORT_DIPSETTING( 0x01, DEF_STR( 1C_5C ) )
- PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW1:4,5")
+ PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("DSW1:4,5")
PORT_DIPSETTING( 0x00, DEF_STR( 3C_1C ) )
PORT_DIPSETTING( 0x10, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x18, DEF_STR( 1C_1C ) )
@@ -227,14 +227,14 @@ static INPUT_PORTS_START( shtrider )
PORT_DIPUNKNOWN_DIPLOC( 0x80, 0x80, "DSW1:8" )
PORT_START("DSW2")
- PORT_DIPNAME( 0x01, 0x01, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:1")
+ PORT_DIPNAME( 0x01, 0x01, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("DSW2:1")
PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
- PORT_DIPNAME( 0x02, 0x02, "Speed Display" ) PORT_DIPLOCATION("DSW2:2")
+ PORT_DIPNAME( 0x02, 0x02, "Speed Display" ) PORT_DIPLOCATION("DSW2:2")
PORT_DIPSETTING( 0x02, "km/h" )
PORT_DIPSETTING( 0x00, "mph" )
PORT_DIPUNKNOWN_DIPLOC( 0x04, 0x04, "DSW2:3" )
- PORT_DIPNAME( 0x08, 0x08, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:4")
+ PORT_DIPNAME( 0x08, 0x08, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("DSW2:4")
PORT_DIPSETTING( 0x08, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x00, DEF_STR( Cocktail ) )
PORT_DIPUNKNOWN_DIPLOC( 0x10, 0x10, "DSW2:5" )
@@ -367,7 +367,7 @@ ROM_START( travrusa )
ROM_LOAD( "tbp24s10.3", 0x0220, 0x0100, CRC(76062638) SHA1(7378a26cf455d9d3df90929dc665870514c34b54) ) /* sprite lookup table */
ROM_END
- /* Bootleg - "American Top" printed on title - (c) 1983 I.P. - Zippy Race graphic logo is blanked out - Main ROM0-ROM3 test NG */
+ /* Bootleg - "American Top" printed on title - (c) 1983 I.P. - Zippy Race graphic logo is blanked out - Main ROM0-ROM3 test NG */
ROM_START( travrusab )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "at4.m3", 0x0000, 0x2000, CRC(704ce6e4) SHA1(77385d853e3d5085c6ab155417e2b42212aff6fc) )
@@ -386,7 +386,7 @@ ROM_START( travrusab )
ROM_REGION( 0x06000, "gfx2", 0 )
ROM_LOAD( "8.n3", 0x0000, 0x2000, CRC(00c0f46b) SHA1(5fccc188af653785f3fc0f9d36dbbbab472f6fdc) )
ROM_LOAD( "9.m3", 0x2000, 0x2000, CRC(73ade73b) SHA1(4da012d71e7c1f46407343cc8d4fbe0397b7db71) )
- ROM_LOAD( "10.k3", 0x4000, 0x2000, CRC(fcfeaa69) SHA1(a958caf70d2dc4a80298a395cb48db210e6ca16b) )
+ ROM_LOAD( "10.k3", 0x4000, 0x2000, CRC(fcfeaa69) SHA1(a958caf70d2dc4a80298a395cb48db210e6ca16b) )
ROM_REGION( 0x0320, "proms", 0 )
ROM_LOAD( "mmi6349.ij", 0x0000, 0x0200, CRC(c9724350) SHA1(1fac20cdc0a53d94e8f67b49d7dd71d1b9f1f7ef) ) /* character palette - last $100 are unused */
@@ -430,7 +430,7 @@ Unfortunately the eproms labels have dissapeared, so I name it similar to Traver
Rom Info
-snd.a1 ------ sound code, 100% identical to Traverse Usa/Zippy race
+snd.a1 ------ sound code, 100% identical to Traverse Usa/Zippy race
mt1-1.e3 \
mt1-2.c3 -- Backgrounds?, 100% identical to Traverse Usa/Zippy race
@@ -438,7 +438,7 @@ mt1-3.a3 /
mt1-4.m3 \
mt1-5.l3 ==
-mt1-6.k3 == Main cpu. Different from the other sets
+mt1-6.k3 == Main cpu. Different from the other sets
mt1-7.j3 /
diff --git a/src/mame/includes/bfm_sc45.h b/src/mame/includes/bfm_sc45.h
index 70974db0097..8ffcd06e859 100644
--- a/src/mame/includes/bfm_sc45.h
+++ b/src/mame/includes/bfm_sc45.h
@@ -21,7 +21,6 @@ public:
m_vfd0(*this, "vfd0"),
m_ymz(*this, "ymz")
{
-
}
public:
diff --git a/src/mame/includes/bfm_sc5.h b/src/mame/includes/bfm_sc5.h
index 6a2eccf5e57..8a635b0c568 100644
--- a/src/mame/includes/bfm_sc5.h
+++ b/src/mame/includes/bfm_sc5.h
@@ -24,4 +24,3 @@ public:
};
-
diff --git a/src/mame/includes/midtunit.h b/src/mame/includes/midtunit.h
index 832f13ed842..1e024378477 100644
--- a/src/mame/includes/midtunit.h
+++ b/src/mame/includes/midtunit.h
@@ -71,7 +71,7 @@ public:
void register_state_saving();
void init_tunit_generic(int sound);
void init_nbajam_common(int te_protection);
-
+
/* CMOS-related variables */
UINT8 cmos_write_enable;
@@ -90,7 +90,7 @@ public:
const UINT8 *jdredd_prot_table;
UINT8 jdredd_prot_index;
UINT8 jdredd_prot_max;
-
+
};
/*----------- defined in video/midtunit.c -----------*/
extern UINT8 midtunit_gfx_rom_large;
diff --git a/src/mame/includes/pgm.h b/src/mame/includes/pgm.h
index 6e10c8d82cb..d92ea4ae36c 100644
--- a/src/mame/includes/pgm.h
+++ b/src/mame/includes/pgm.h
@@ -373,14 +373,14 @@ public:
UINT32 m_kb_game_id;
- UINT16 m_kb_prot_hold;
- UINT16 m_kb_prot_hilo;
- UINT16 m_kb_prot_hilo_select;
+ UINT16 m_kb_prot_hold;
+ UINT16 m_kb_prot_hilo;
+ UINT16 m_kb_prot_hilo_select;
int m_kb_cmd;
int m_kb_reg;
int m_kb_ptr;
- UINT8 m_kb_swap;
+ UINT8 m_kb_swap;
UINT32 m_kb_regs[0x10];
required_shared_ptr<UINT16> m_sharedprotram;
@@ -415,9 +415,9 @@ public:
int m_olds_ptr;
UINT16 m_olds_bs;
UINT16 m_olds_cmd3;
- UINT16 m_olds_prot_hold;
- UINT16 m_olds_prot_hilo;
- UINT16 m_olds_prot_hilo_select;
+ UINT16 m_olds_prot_hold;
+ UINT16 m_olds_prot_hilo;
+ UINT16 m_olds_prot_hilo_select;
const UINT8 *m_olds_prot_hilo_source2;
required_shared_ptr<UINT16> m_sharedprotram;
diff --git a/src/mame/includes/tx1.h b/src/mame/includes/tx1.h
index 4f2eb8df9f2..43a4fe224d1 100644
--- a/src/mame/includes/tx1.h
+++ b/src/mame/includes/tx1.h
@@ -40,8 +40,8 @@ struct math_t
UINT32 i0ff;
UINT16 retval;
UINT16 muxlatch; // TX-1
- int dbgaddr;
- int dbgpc;
+ int dbgaddr;
+ int dbgpc;
};
/*
diff --git a/src/mame/includes/zodiack.h b/src/mame/includes/zodiack.h
index 4fe4bb6bbcd..c925fe2e6bf 100644
--- a/src/mame/includes/zodiack.h
+++ b/src/mame/includes/zodiack.h
@@ -63,4 +63,3 @@ public:
INTERRUPT_GEN_MEMBER(zodiack_sound_nmi_gen);
INTERRUPT_GEN_MEMBER(zodiack_main_nmi_gen);
};
-
diff --git a/src/mame/machine/megavdp.c b/src/mame/machine/megavdp.c
index aa48333cc9e..19b1171d5aa 100644
--- a/src/mame/machine/megavdp.c
+++ b/src/mame/machine/megavdp.c
@@ -179,7 +179,7 @@ void sega_genesis_vdp_device::device_start()
m_render_line_raw = auto_alloc_array(machine(), UINT16, machine().primary_screen->width());
- // FIXME: are these all needed? I'm pretty sure some of these (most?) are just helpers which don't need to be saved,
+ // FIXME: are these all needed? I'm pretty sure some of these (most?) are just helpers which don't need to be saved,
// but better safe than sorry...
save_pointer(NAME(m_sprite_renderline), 1024);
save_pointer(NAME(m_highpri_renderline), 320);
diff --git a/src/mame/machine/naomicrypt.c b/src/mame/machine/naomicrypt.c
index 4aaf76ad87d..911a00a9c44 100644
--- a/src/mame/machine/naomicrypt.c
+++ b/src/mame/machine/naomicrypt.c
@@ -26,7 +26,6 @@ struct game_keys
static const struct game_keys keys_table[] =
{
-
// name key gameid # year
// M2
{ "wldkicks", 0x00ae2901 }, // 25209801 2000
@@ -69,7 +68,7 @@ static const struct game_keys keys_table[] =
{ "samba2k", 0x001702cf }, // 840-0047 2000
{ "alienfnt", 0x00174343 }, // 840-0048 2001
{ "alienfnta", 0x00174343 }, // 840-0048 2001
- { "crackdj2", 0x00428247 }, // 840-0068 2001
+ { "crackdj2", 0x00428247 }, // 840-0068 2001
{ "vf4cart", 0x02ef2f96 }, // 840-0080 2002
{ "pstone", 0x000e69c1 }, // 841-0001 1999
{ "suchie3", 0x000368e1 }, // 841-0002 1999
diff --git a/src/mame/machine/pgmprot4.c b/src/mame/machine/pgmprot4.c
index fef29a20347..5ce8f57bb46 100644
--- a/src/mame/machine/pgmprot4.c
+++ b/src/mame/machine/pgmprot4.c
@@ -446,7 +446,7 @@ void pgm_022_025_state::IGS022_reset()
src >>= 1;
-// printf("Auto-DMA %04x %04x %04x %04x\n",src,dst,size,mode);
+// printf("Auto-DMA %04x %04x %04x %04x\n",src,dst,size,mode);
IGS022_do_dma(src,dst,size,mode);
@@ -598,8 +598,8 @@ WRITE16_MEMBER(pgm_022_025_state::killbld_igs025_prot_w )
killbld_protection_calculate_hold(m_kb_cmd & 0x0f, data & 0xff);
break;
- // default:
- // logerror("%06X: ASIC25 W CMD %X VAL %X\n", space.device().safe_pc(), m_kb_cmd, data);
+ // default:
+ // logerror("%06X: ASIC25 W CMD %X VAL %X\n", space.device().safe_pc(), m_kb_cmd, data);
}
}
}
@@ -611,14 +611,13 @@ READ16_MEMBER(pgm_022_025_state::killbld_igs025_prot_r )
switch (m_kb_cmd)
{
case 0x00:
- return BITSWAP8((m_kb_swap+1)&0xff, 0,1,2,3,4,5,6,7); // dw3
+ return BITSWAP8((m_kb_swap+1)&0xff, 0,1,2,3,4,5,6,7); // dw3
case 0x01:
return m_kb_reg & 0x7f;
case 0x05:
{
-
logerror ("ptr: %d\n", m_kb_ptr);
switch (m_kb_ptr)
@@ -631,7 +630,7 @@ READ16_MEMBER(pgm_022_025_state::killbld_igs025_prot_r )
case 3:
return 0x3f00 | ((m_kb_game_id >> 16) & 0xff);
-
+
case 4:
return 0x3f00 | ((m_kb_game_id >> 24) & 0xff);
@@ -648,7 +647,7 @@ READ16_MEMBER(pgm_022_025_state::killbld_igs025_prot_r )
return 0; // is this used?
//default:
- // logerror("%06X: ASIC25 R CMD %X\n", space.device().safe_pc(), m_kb_cmd);
+ // logerror("%06X: ASIC25 R CMD %X\n", space.device().safe_pc(), m_kb_cmd);
}
}
@@ -832,7 +831,7 @@ INPUT_PORTS_START( dw3 )
PORT_MODIFY("Region") /* Region - supplied by protection device */
PORT_CONFNAME( 0x000f, 0x0006, DEF_STR( Region ) )
-// PORT_CONFSETTING( 0x0000, "0" )
+// PORT_CONFSETTING( 0x0000, "0" )
PORT_CONFSETTING( 0x0001, "1" )
PORT_CONFSETTING( 0x0002, "2" )
PORT_CONFSETTING( 0x0003, "3" )
diff --git a/src/mame/machine/pgmprot6.c b/src/mame/machine/pgmprot6.c
index a45eb4e894b..8b1b217a66c 100644
--- a/src/mame/machine/pgmprot6.c
+++ b/src/mame/machine/pgmprot6.c
@@ -183,7 +183,7 @@ void pgm_028_025_state::IGS028_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT1
UINT16 param = mode >> 8;
UINT16 *PROTROM = (UINT16*)memregion("user1")->base();
-// logerror ("mode: %2.2x, src: %4.4x, dst: %4.4x, size: %4.4x, data: %4.4x\n", (mode &0xf), src, dst, size, mode);
+// logerror ("mode: %2.2x, src: %4.4x, dst: %4.4x, size: %4.4x, data: %4.4x\n", (mode &0xf), src, dst, size, mode);
mode &= 0x0f;
@@ -222,7 +222,7 @@ void pgm_028_025_state::IGS028_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT1
break;
//default:
- // logerror ("DMA mode unknown!!!\nsrc:%4.4x, dst: %4.4x, size: %4.4x, mode: %4.4x\n", src, dst, size, mode);
+ // logerror ("DMA mode unknown!!!\nsrc:%4.4x, dst: %4.4x, size: %4.4x, mode: %4.4x\n", src, dst, size, mode);
}
}
@@ -252,13 +252,13 @@ void pgm_028_025_state::olds_protection_calculate_hilo() // calculated in routin
source = olds_source_data[ioport("Region")->read() - 1][m_olds_prot_hilo_select];
- if (m_olds_prot_hilo_select & 1) // $8178fa
+ if (m_olds_prot_hilo_select & 1) // $8178fa
{
- m_olds_prot_hilo = (m_olds_prot_hilo & 0x00ff) | (source << 8); // $8178d8
+ m_olds_prot_hilo = (m_olds_prot_hilo & 0x00ff) | (source << 8); // $8178d8
}
else
{
- m_olds_prot_hilo = (m_olds_prot_hilo & 0xff00) | (source << 0); // $8178d8
+ m_olds_prot_hilo = (m_olds_prot_hilo & 0xff00) | (source << 0); // $8178d8
}
}
@@ -284,14 +284,14 @@ WRITE16_MEMBER(pgm_028_025_state::olds_w )
{
UINT16 cmd = m_sharedprotram[0x3026 / 2];
- // logerror ("command: %x\n", cmd);
+ // logerror ("command: %x\n", cmd);
switch (cmd)
{
case 0x12:
{
- UINT16 mode = m_sharedprotram[0x303e / 2]; // ?
- UINT16 src = m_sharedprotram[0x306a / 2] >> 1; // ?
+ UINT16 mode = m_sharedprotram[0x303e / 2]; // ?
+ UINT16 src = m_sharedprotram[0x306a / 2] >> 1; // ?
UINT16 dst = m_sharedprotram[0x3084 / 2] & 0x1fff;
UINT16 size = m_sharedprotram[0x30a2 / 2] & 0x1fff;
@@ -304,15 +304,15 @@ WRITE16_MEMBER(pgm_028_025_state::olds_w )
UINT16 p1 = m_sharedprotram[0x3050 / 2];
UINT16 p2 = m_sharedprotram[0x3082 / 2];
- // logerror ("p1: %4.4x, p2: %4.4x\n", p1, p2);
+ // logerror ("p1: %4.4x, p2: %4.4x\n", p1, p2);
if (p2 == 0x02)
olds_write_reg(p1, olds_read_reg(p1) + 0x10000);
}
break;
- // default:
- // logerror ("unemulated command!\n");
+ // default:
+ // logerror ("unemulated command!\n");
}
m_olds_cmd3 = ((data >> 4) + 1) & 0x3;
@@ -335,8 +335,8 @@ WRITE16_MEMBER(pgm_028_025_state::olds_w )
olds_protection_calculate_hold(m_olds_cmd & 0x0f, data & 0xff);
break;
- // default:
- // logerror ("unemulated write mode!\n");
+ // default:
+ // logerror ("unemulated write mode!\n");
}
}
}
@@ -373,7 +373,7 @@ READ16_MEMBER(pgm_028_025_state::olds_r )
case 5:
default: // >= 5
- return 0x3f00 | BITSWAP8(m_olds_prot_hold, 5,2,9,7,10,13,12,15); // $817906
+ return 0x3f00 | BITSWAP8(m_olds_prot_hold, 5,2,9,7,10,13,12,15); // $817906
}
}
@@ -390,25 +390,25 @@ MACHINE_RESET_MEMBER(pgm_028_025_state,olds)
{
MACHINE_RESET_CALL_MEMBER(pgm);
-// written by protection device
-// there seems to be an auto-dma that writes from $401000-402573?
+// written by protection device
+// there seems to be an auto-dma that writes from $401000-402573?
m_sharedprotram[0x1000/2] = 0x4749; // 'IGS.28'
m_sharedprotram[0x1002/2] = 0x2E53;
m_sharedprotram[0x1004/2] = 0x3832;
m_sharedprotram[0x3064/2] = 0xB315; // crc or status check?
-// Should these be written by command 64??
-// m_sharedprotram[0x2a00/2] = 0x0000; // ?
-// m_sharedprotram[0x2a02/2] = 0x0000; // ?
+// Should these be written by command 64??
+// m_sharedprotram[0x2a00/2] = 0x0000; // ?
+// m_sharedprotram[0x2a02/2] = 0x0000; // ?
m_sharedprotram[0x2a04/2] = 0x0002; // ?
-// m_sharedprotram[0x2a06/2] = 0x0000; // ?
-// m_sharedprotram[0x2ac0/2] = 0x0000; // ?
+// m_sharedprotram[0x2a06/2] = 0x0000; // ?
+// m_sharedprotram[0x2ac0/2] = 0x0000; // ?
m_sharedprotram[0x2ac2/2] = 0x0001; // ?
-// m_sharedprotram[0x2e00/2] = 0x0000; // ?
-// m_sharedprotram[0x2e02/2] = 0x0000; // ?
-// m_sharedprotram[0x2e04/2] = 0x0000; // ?
+// m_sharedprotram[0x2e00/2] = 0x0000; // ?
+// m_sharedprotram[0x2e02/2] = 0x0000; // ?
+// m_sharedprotram[0x2e04/2] = 0x0000; // ?
m_sharedprotram[0x2e06/2] = 0x0009; // seconds on char. select timer
-// m_sharedprotram[0x2e08/2] = 0x0000; // ?
+// m_sharedprotram[0x2e08/2] = 0x0000; // ?
m_sharedprotram[0x2e0a/2] = 0x0006; // ?
}
diff --git a/src/mame/mame.lst b/src/mame/mame.lst
index 29aac36b3dc..cab599e06db 100644
--- a/src/mame/mame.lst
+++ b/src/mame/mame.lst
@@ -50,9 +50,9 @@ puckmod // (c) 1981 Namco
pacmod // (c) 1981 Midway
newpuc2 // hack
newpuc2b // hack
-pacuman // bootleg
+pacuman // bootleg
newpuckx // hack
-pacmansp // hack
+pacmansp // hack
pacheart // hack
bucaner // hack
hangly // hack
@@ -65,7 +65,7 @@ abscam // hack
crush // (c) 1981 Kural Samno Electric Ltd
crushbl // bootleg
crushbl2 // bootleg
-crushbl3 // bootleg
+crushbl3 // bootleg
crush2 // (c) 1981 Kural Esco Electric Ltd - bootleg?
crush3 // Kural Electric Ltd - bootleg?
crush4 // Kural TWT
@@ -98,7 +98,7 @@ mspacman // (c) 1981 Midway // made by General Computer
mspacmnf // hack
mspacmat // hack
msheartb // hack
-mspacmanbg // bootleg
+mspacmanbg // bootleg
woodpeck // (c) 1981 Amenip (Palcom Queen River)
woodpeca // (c) 1981 Amenip Nova Games Ltd.
mspacmab // bootleg
@@ -162,7 +162,7 @@ galaxiana // (c) Namco
galaxianm // (c) Midway
galaxianmo // (c) Midway
galaxiant // (c) Taito
-galaxrf // bootleg (Recreativos Franco)
+galaxrf // bootleg (Recreativos Franco)
superg // hack
galapx // hack
moonaln // [Nichibutsu] (Karateco license) or hack
@@ -184,7 +184,7 @@ gteikoku // (c) Irem
gteikokb // bootleg
gteikob2 // bootleg
galemp // (c) Taito do Brasil
-asideral // bootleg
+asideral // bootleg
spacbatt // bootleg
spacbat2 // bootleg
spacempr // bootleg
@@ -227,7 +227,7 @@ starfgmc // bootleg
spcdrag // bootleg
stera // bootleg
spcdraga // bootleg
-mooncreg // bootleg
+mooncreg // bootleg
mooncrs3 // bootleg
mooncrs4 // bootleg
fantazia // bootleg
@@ -243,7 +243,7 @@ eagle // [1980] Centuri
eagle2 // [1980] Centuri
eagle3 // [1980] Centuri
spctbird // (c) Fortrek
-mooncptc // bootleg (Petaco S.A.)
+mooncptc // bootleg (Petaco S.A.)
fantastc // (c) Taito (Brazil) - rewrite of Galaga
timefgtr // (c) Taito (Brazil) - rewrite of Time Pilot
kong // (c) Taito (Brazil) - rewrite of Donkey Kong
@@ -671,7 +671,7 @@ falconz // bootleg
vautourz // bootleg
griffon // bootleg (Videotron)
nextfase // bootleg
-phoenixs // bootleg (Sonic)
+phoenixs // bootleg (Sonic)
pleiads // (c) 1981 Tehkan
pleiadsb2 // bootleg
pleiadbl // bootleg
@@ -1680,7 +1680,7 @@ vs10yardu // (c) 1983/1984
travrusa // (c) 1983
travrusab // (c) 1983 I.P. (bootleg)
motorace // (c) 1983 Williams license
-mototour // (c) 1983 Tecfri
+mototour // (c) 1983 Tecfri
shtrider // (c) 1984 Seibu Kaihatsu
shtridera // (c) 1984 Seibu Kaihatsu
wilytowr // M63 (c) 1984
@@ -3059,7 +3059,7 @@ megaman // 06/10/1995 (c) 1995 (USA)
megamana // 06/10/1995 (c) 1995 (Asia)
rockmanj // 22/09/1995 (c) 1995 (Japan)
fcrash // bootleg of Final Fight
-ffightbl //
+ffightbl //
ganbare // 11/04/2000 (c) 2000 (Japan)
// Capcom CPS2 games
@@ -3836,7 +3836,7 @@ pang // (c) 1989 Mitchell (World)
pangb // bootleg
pangbold // bootleg
pangba // bootleg
-pangb2 // bootleg
+pangb2 // bootleg
bbros // (c) 1989 Capcom (US) not listed on Capcom's site
pompingw // (c) 1989 Mitchell (Japan)
cbasebal // 10/1989 (c) 1989 Capcom (Japan) (different hardware)
@@ -4317,7 +4317,7 @@ altbeast4 // (c) 1988 (MC-8123B)
altbeast2 // (c) 1988 (MC-8123B)
altbeastj1 // (c) 1988 (protected)
altbeastj3 // (c) 1988 (FD1094, decrypted)
-altbeastbl //
+altbeastbl //
aurail // (c) 1990 Sega / Westone
aurail1 // (c) 1990 Sega / Westone (FD1089B, decrypted)
aurailj // (C) 1990 Sega / Westone (FD1089A, decrypted)
@@ -5078,7 +5078,7 @@ gundmct // 2001.03 Mobile Suit Gundam: Federation Vs. Zeon (cartridge)
// 2001.03 Star Horse Progress (Rev A)
dygolf // 2001.04 Dynamic Golf / Virtua Golf (Rev A)
// 2001.04 Shakatto Tambourine Motto Norinori Shinkyoku Tsuika
-shaktmsp // 2001.04 Shakatto Tambourine 2K1 SPR
+shaktmsp // 2001.04 Shakatto Tambourine 2K1 SPR
monkeyba // 2001.05 Monkey Ball
zerogu2 // 2001.05 Zero Gunner 2
cvsgd // 2001.06 Capcom Vs. SNK Millennium Fight 2000 Pro
@@ -5815,7 +5815,7 @@ megaforc // (c) 1985 Tehkan + Video Ware license
baluba // (c) 1986 Able Corp.
bombjack // (c) 1984 Tehkan
bombjack2 // (c) 1984 Tehkan
-bombjackt // (c) 1984 Tehkan + Tecfri license
+bombjackt // (c) 1984 Tehkan + Tecfri license
pbaction // (c) 1985 Tehkan
pbaction2 // (c) 1985 Tehkan
pbaction3 // (c) 1985 Tehkan
@@ -7540,8 +7540,8 @@ laserbat // (c) 1981
lazarian // (c) 1981
catnmous // (c) 1982
catnmousa // (c) 1982
-seabattl // (c) 1980
-seabattla // (c) 1980
+seabattl // (c) 1980
+seabattla // (c) 1980
monymony // (c) 1983
jackrabt // (c) 1984
jackrabt2 // (c) 1984
@@ -7590,7 +7590,7 @@ strahla // UPL-91074 (c) 1992 UPL (Japan)
bjtwin // UPL-93087 (c) 1993 NMK
bjtwina // UPL-93087 (c) 1993 NMK
bjtwinp // UPL-93087 (c) 1993 NMK
-atombjt // bootleg
+atombjt // bootleg
tdragon2 // UPL-93091 (c) 1993 NMK
tdragon2a // UPL-93091 (c) 1993 NMK
bigbang // UPL-93091 (c) 1993 NMK
@@ -7931,7 +7931,7 @@ brod
bagman // (c) 1982
bagnard // (c) 1982
bagnarda // (c) 1982
-bagnardi // (c) 1982 + Itisa license
+bagnardi // (c) 1982 + Itisa license
bagmans // (c) 1982 + Stern license
bagmans2 // (c) 1982 + Stern license
pickin // (c) 1983
@@ -8260,11 +8260,11 @@ spinlbrku // (c) 1990 V-System Co. (US)
spinlbrkj // (c) 1990 V-System Co. (Japan)
pspikes // (c) 1991 Video System Co. (World)
pspikesk // (c) 1991 Video System Co. (Korea)
-pspikesu // (c) 1991 Video System Co. (US)
+pspikesu // (c) 1991 Video System Co. (US)
svolly91 // (c) 1991 Video System Co. (Japan)
pspikesb // bootleg
spikes91 // bootleg
-spikes91b // bootleg
+spikes91b // bootleg
pspikesc // bootleg
karatblz // (c) 1991 Video System Co.
karatblzu // (c) 1991 Video System Co. (US)
@@ -8462,7 +8462,7 @@ galsnewa // (c) 1990 Kaneko
galsnewj // (c) 1990 Kaneko
galsnewk // (c) 1990 Kaneko
galpani2 // (c) 1993 Kaneko
-galpani2e // (c) 1993 Kaneko
+galpani2e // (c) 1993 Kaneko
galpani2g // (c) 1993 Kaneko
galpani2t // (c) 1993 Kaneko
galpani2i // (c) 1993 Kaneko
@@ -8740,7 +8740,7 @@ ikki // TVG17 (c) 1985 Sun Electronics (Japan)
farmer // TVG17 (c) 1985 Sun Electronics
shanghai // (c) 1988 Sunsoft (Sun Electronics)
shangha2 // (c) 1989 Sunsoft (Sun Electronics)
-shangha2a // (c) 1989 Sunsoft (Sun Electronics)
+shangha2a // (c) 1989 Sunsoft (Sun Electronics)
shangha3 // (c) 1993 Sunsoft
heberpop // (c) 1994 Sunsoft / Atlus
blocken // (c) 1994 KID / Visco
@@ -8990,7 +8990,7 @@ zeropnta // (c) 1998
zeropntj // (c) 1998 (Japan)
zeropnt2 // (c) 1999
silkroad // (c) 1999
-silkroada // (c) 1999
+silkroada // (c) 1999
aoh // (c) 2001
// Afega games
@@ -9001,10 +9001,10 @@ redhawke // (c) 1997 Excellent Co., Ltd license
redhawki // (c) 1997 Haedong Corp. license
redhawkb // (c) 1997
grdnstrm // (c) 1998 Apples Industries license
-grdnstrmv //
+grdnstrmv //
grdnstrmk // (c) 1998 (Korea)
redfoxwp2 // (c) 1998 (China)
-redfoxwp2a // (c) 1998 (China)
+redfoxwp2a // (c) 1998 (China)
bubl2000 // (c) 1998 Tuning
hotbubl // (c) 1998 Pandora
popspops // (c) 1999
@@ -9853,7 +9853,7 @@ wallc // (c) 1984 Midcoin
wallca // (c) 1984 Midcoin
wink // (c) 1985 Midcoin
winka // (c) 1985 Midcoin
-24cdjuke // (c) 1988 Midcoin
+24cdjuke // (c) 1988 Midcoin
skyarmy // (c) 1982 Shoei
lethalj // (c) 1996 The Game Room
eggventr // (c) 1997 The Game Room
@@ -9958,7 +9958,7 @@ majorpkr // (c) 1994 PAL System.
su2000 // (c) 1993 Virtuality
boonggab // (c) 2001 Taff System
fresh // (c) Chain Leisure
-stuntair // (c) 1983 Nuova Videotron
+stuntair // (c) 1983 Nuova Videotron
// Success
tonton // (c) 199? Success / Taiyo Jidoki.
@@ -30595,4 +30595,3 @@ bingomana
number1 // 1996 San Remo Games
gluck2 // 1992 Yung Yu / CYE
-
diff --git a/src/mame/video/snes.c b/src/mame/video/snes.c
index 9995fcef274..61500cdad6e 100644
--- a/src/mame/video/snes.c
+++ b/src/mame/video/snes.c
@@ -1687,7 +1687,7 @@ void snes_ppu_class::ppu_start(running_machine &machine)
/* Init oam RAM */
memset((UINT8 *)m_oam_ram, 0xff, SNES_OAM_SIZE);
-
+
for (int i = 0; i < 2; i++)
{
state_save_register_item(machine, "snes_ppu", NULL, i, m_scanlines[i].enable);
diff --git a/src/mame/video/snookr10.c b/src/mame/video/snookr10.c
index af63a76b354..f5a6b76396d 100644
--- a/src/mame/video/snookr10.c
+++ b/src/mame/video/snookr10.c
@@ -103,7 +103,7 @@ TILE_GET_INFO_MEMBER(snookr10_state::get_bg_tile_info)
/**********************************************************
- Apple 10 palette and tile matrix / video RAM
+ Apple 10 palette and tile matrix / video RAM
are encrypted/scrambled.
For more information, see the driver notes.
@@ -172,7 +172,7 @@ TILE_GET_INFO_MEMBER(snookr10_state::apple10_get_bg_tile_info)
/**********************************************************
- Crystals Colours palette and tile matrix / video RAM
+ Crystals Colours palette and tile matrix / video RAM
are encrypted/scrambled.
For more information, see the driver notes.
diff --git a/src/mess/audio/gb.c b/src/mess/audio/gb.c
index adb325206a7..a318e33d698 100644
--- a/src/mess/audio/gb.c
+++ b/src/mess/audio/gb.c
@@ -124,7 +124,7 @@ void gameboy_sound_device::device_config_complete()
//-------------------------------------------------
void gameboy_sound_device::device_start()
-{
+{
m_channel = machine().sound().stream_alloc(*this, 0, 2, machine().sample_rate(), this);
m_rate = machine().sample_rate();
@@ -249,14 +249,14 @@ void gameboy_sound_device::device_reset()
memset(&m_snd_2, 0, sizeof(m_snd_2));
memset(&m_snd_3, 0, sizeof(m_snd_3));
memset(&m_snd_4, 0, sizeof(m_snd_4));
-
+
/* Calculate the envelope and sweep tables */
for (int i = 0; i < 8; i++)
{
m_env_length_table[i] = (i * ((1 << FIXED_POINT) / 64) * m_rate) >> FIXED_POINT;
m_swp_time_table[i] = (((i << FIXED_POINT) / 128) * m_rate) >> (FIXED_POINT - 1);
}
-
+
/* Calculate the period tables */
for (int i = 0; i < MAX_FREQUENCIES; i++)
{
@@ -273,15 +273,15 @@ void gameboy_sound_device::device_reset()
m_period_mode4_table[i][j] = ((1 << FIXED_POINT) / (524288 / ((i == 0) ? 0.5 : i) / (1 << (j + 1)))) * m_rate;
}
}
-
+
/* Calculate the length table */
for (int i = 0; i < 64; i++)
m_length_table[i] = ((64 - i) * ((1 << FIXED_POINT)/256) * m_rate) >> FIXED_POINT;
-
+
/* Calculate the length table for mode 3 */
for (int i = 0; i < 256; i++)
m_length_mode3_table[i] = ((256 - i) * ((1 << FIXED_POINT)/256) * m_rate) >> FIXED_POINT;
-
+
sound_w_internal(NR52, 0x00);
m_snd_regs[AUD3W0] = 0xac;
m_snd_regs[AUD3W1] = 0xdd;
@@ -314,7 +314,7 @@ READ8_MEMBER( gameboy_sound_device::wave_r )
READ8_MEMBER( gameboy_sound_device::sound_r )
{
- switch (offset)
+ switch (offset)
{
case 0x05:
case 0x0f:
@@ -333,14 +333,13 @@ WRITE8_MEMBER( gameboy_sound_device::wave_w )
WRITE8_MEMBER( gameboy_sound_device::sound_w )
{
-
/* change in registers so update first */
m_channel->update();
-
+
/* Only register NR52 is accessible if the sound controller is disabled */
if (!m_snd_control.on && offset != NR52)
return;
-
+
sound_w_internal(offset, data);
}
@@ -536,7 +535,7 @@ void gameboy_sound_device::sound_w_internal( int offset, UINT8 data )
}
}
-
+
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
@@ -544,11 +543,11 @@ void gameboy_sound_device::sound_w_internal( int offset, UINT8 data )
void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
stream_sample_t sample, left, right, mode4_mask;
-
+
while (samples-- > 0)
{
left = right = 0;
-
+
/* Mode 1 - Wave with Envelope and Sweep */
if (m_snd_1.on)
{
@@ -563,7 +562,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_1.pos = 0;
m_snd_1.signal = -m_snd_1.signal;
}
-
+
if (m_snd_1.length && m_snd_1.mode)
{
m_snd_1.count++;
@@ -573,7 +572,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_regs[NR52] &= 0xFE;
}
}
-
+
if (m_snd_1.env_length)
{
m_snd_1.env_count++;
@@ -587,7 +586,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_1.env_value = 15;
}
}
-
+
if (m_snd_1.swp_time)
{
m_snd_1.swp_count++;
@@ -611,17 +610,17 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_1.frequency = MAX_FREQUENCIES - 1;
}
}
-
+
m_snd_1.period = m_period_table[m_snd_1.frequency];
}
}
-
+
if (m_snd_control.mode1_left)
left += sample;
if (m_snd_control.mode1_right)
right += sample;
}
-
+
/* Mode 2 - Wave with Envelope */
if (m_snd_2.on)
{
@@ -636,7 +635,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_2.pos = 0;
m_snd_2.signal = -m_snd_2.signal;
}
-
+
if (m_snd_2.length && m_snd_2.mode)
{
m_snd_2.count++;
@@ -646,7 +645,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_regs[NR52] &= 0xFD;
}
}
-
+
if (m_snd_2.env_length)
{
m_snd_2.env_count++;
@@ -660,13 +659,13 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_2.env_value = 15;
}
}
-
+
if (m_snd_control.mode2_left)
left += sample;
if (m_snd_control.mode2_right)
right += sample;
}
-
+
/* Mode 3 - Wave patterns from WaveRAM */
if (m_snd_3.on)
{
@@ -679,12 +678,12 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
sample >>= 4;
}
sample = (sample & 0xF) - 8;
-
+
if (m_snd_3.level)
sample >>= (m_snd_3.level - 1);
else
sample = 0;
-
+
m_snd_3.pos++;
if (m_snd_3.pos >= ((UINT32)(((m_snd_3.period) >> 21)) + m_snd_3.duty))
{
@@ -702,7 +701,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_3.dutycount = 0;
}
}
-
+
if (m_snd_3.length && m_snd_3.mode)
{
m_snd_3.count++;
@@ -712,13 +711,13 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_regs[NR52] &= 0xFB;
}
}
-
+
if (m_snd_control.mode3_left)
left += sample;
if (m_snd_control.mode3_right)
right += sample;
}
-
+
/* Mode 4 - Noise with Envelope */
if (m_snd_4.on)
{
@@ -745,7 +744,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_4.ply_value &= (m_snd_4.ply_step ? 0x7f : 0x7fff);
m_snd_4.signal = (INT8)m_snd_4.ply_value;
}
-
+
if (m_snd_4.length && m_snd_4.mode)
{
m_snd_4.count++;
@@ -755,7 +754,7 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_regs[NR52] &= 0xF7;
}
}
-
+
if (m_snd_4.env_length)
{
m_snd_4.env_count++;
@@ -769,26 +768,26 @@ void gameboy_sound_device::sound_stream_update(sound_stream &stream, stream_samp
m_snd_4.env_value = 15;
}
}
-
+
if (m_snd_control.mode4_left)
left += sample;
if (m_snd_control.mode4_right)
right += sample;
}
-
+
/* Adjust for master volume */
left *= m_snd_control.vol_left;
right *= m_snd_control.vol_right;
-
+
/* pump up the volume */
left <<= 6;
right <<= 6;
-
+
/* Update the buffers */
*(outputs[0]++) = left;
*(outputs[1]++) = right;
}
-
+
m_snd_regs[NR52] = (m_snd_regs[NR52]&0xf0) | m_snd_1.on | (m_snd_2.on << 1) | (m_snd_3.on << 2) | (m_snd_4.on << 3);
}
diff --git a/src/mess/audio/gb.h b/src/mess/audio/gb.h
index a12e089c267..f56ccce8c42 100644
--- a/src/mess/audio/gb.h
+++ b/src/mess/audio/gb.h
@@ -64,7 +64,7 @@ public:
DECLARE_READ8_MEMBER(wave_r);
DECLARE_WRITE8_MEMBER(sound_w);
DECLARE_WRITE8_MEMBER(wave_w);
-
+
protected:
// device-level overrides
virtual void device_config_complete();
@@ -80,7 +80,7 @@ private:
sound_stream *m_channel;
int m_rate;
-
+
INT32 m_env_length_table[8];
INT32 m_swp_time_table[8];
UINT32 m_period_table[MAX_FREQUENCIES];
@@ -88,13 +88,13 @@ private:
UINT32 m_period_mode4_table[8][16];
UINT32 m_length_table[64];
UINT32 m_length_mode3_table[256];
-
+
struct SOUND m_snd_1;
struct SOUND m_snd_2;
struct SOUND m_snd_3;
struct SOUND m_snd_4;
struct SOUNDC m_snd_control;
-
+
UINT8 m_snd_regs[0x30];
};
diff --git a/src/mess/audio/lynx.c b/src/mess/audio/lynx.c
index e1442998a76..74ebb659339 100644
--- a/src/mess/audio/lynx.c
+++ b/src/mess/audio/lynx.c
@@ -97,7 +97,7 @@ const device_type LYNX2_SND = &device_creator<lynx2_sound_device>;
lynx_sound_device::lynx_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, LYNX_SND, "Mikey", tag, owner, clock, "lynx_sound", __FILE__),
device_sound_interface(mconfig, *this)
-{
+{
m_timer_delegate = lynx_sound_timer_delegate();
}
@@ -156,10 +156,10 @@ void lynx_sound_device::register_save()
}
void lynx_sound_device::init()
-{
+{
m_shift_mask = auto_alloc_array_clear(machine(), int, 512);
m_shift_xor = auto_alloc_array_clear(machine(), int, 4096);
-
+
for (int i = 0; i < 512; i++)
{
m_shift_mask[i] = 0;
@@ -173,7 +173,7 @@ void lynx_sound_device::init()
if (i & 0x80) m_shift_mask[i] |= 0x800;
if (i & 0x100) m_shift_mask[i] |= 0x80;
}
-
+
for (int i = 0; i < 4096; i++)
{
m_shift_xor[i] = 1;
@@ -182,7 +182,7 @@ void lynx_sound_device::init()
if (i & j)
m_shift_xor[i] ^= 1;
}
- }
+ }
}
void lynx_sound_device::device_start()
@@ -238,9 +238,9 @@ void lynx_sound_device::reset_channel(LYNX_AUDIO *channel)
void lynx_sound_device::count_down(int nr)
{
LYNX_AUDIO *channel = &m_audio[nr];
- if (channel->reg.control1 & 8 && (channel->reg.control1 & 7) != 7)
+ if (channel->reg.control1 & 8 && (channel->reg.control1 & 7) != 7)
return;
- if (nr == 0)
+ if (nr == 0)
m_mixer_channel->update();
//if ((channel->reg.control1 & 0x0f) == 0x0f) //count down if linking enabled and count enabled
channel->count--;
@@ -250,17 +250,17 @@ void lynx_sound_device::shift(int chan_nr)
{
INT16 out_temp;
LYNX_AUDIO *channel;
-
+
assert(chan_nr < 4);
- channel = &m_audio[chan_nr];
+ channel = &m_audio[chan_nr];
//channel->shifter = ((channel->shifter<<1)&0xffe) | (m_shift_xor[ channel->shifter & channel->mask ]&1);
// alternative method (functionally the same as above)
UINT8 xor_out = 0;
for (int bit = 0; bit < 12; bit++)
{
- if ((channel->mask >> bit) & 1)
+ if ((channel->mask >> bit) & 1)
xor_out ^= (channel->shifter >> bit) & 1;
}
channel->shifter = ((channel->shifter << 1) & 0xffe) | (xor_out ^ 1); // output of xor is inverted
@@ -284,7 +284,7 @@ void lynx_sound_device::shift(int chan_nr)
case 0: count_down(1); break;
case 1: count_down(2); break;
case 2: count_down(3); break;
- case 3:
+ case 3:
if (!m_timer_delegate.isnull())
m_timer_delegate();
break;
@@ -294,10 +294,10 @@ void lynx_sound_device::shift(int chan_nr)
void lynx_sound_device::execute(int chan_nr)
{
LYNX_AUDIO *channel;
-
+
assert(chan_nr < 4);
-
- channel = &m_audio[chan_nr];
+
+ channel = &m_audio[chan_nr];
if (channel->reg.control1 & 8) // count enable
{
@@ -320,7 +320,7 @@ void lynx_sound_device::execute(int chan_nr)
for (; (channel->ticks >= t) && (channel->count >= 0); channel->ticks -= t) // at least one sampled worth of time left, timer not expired
channel->count--;
- if (channel->ticks < t)
+ if (channel->ticks < t)
break;
if (channel->count < 0)
@@ -355,7 +355,7 @@ READ8_MEMBER(lynx_sound_device::read)
if (offset < 0x40)
{
- switch (offset & 7)
+ switch (offset & 7)
{
case 0:
value = channel->reg.volume;
@@ -418,7 +418,7 @@ WRITE8_MEMBER(lynx_sound_device::write)
if (offset < 0x40)
{
- switch (offset & 0x07)
+ switch (offset & 0x07)
{
// Volume control (signed)
case 0:
@@ -489,7 +489,7 @@ void lynx_sound_device::sound_stream_update(sound_stream &stream, stream_sample_
{
int v;
stream_sample_t *buffer = outputs[0];
-
+
for (int i = 0; i < samples; i++, buffer++)
{
*buffer = 0;
@@ -510,7 +510,7 @@ void lynx2_sound_device::sound_stream_update(sound_stream &stream, stream_sample
{
stream_sample_t *left=outputs[0], *right=outputs[1];
int v;
-
+
for (int i = 0; i < samples; i++, left++, right++)
{
*left = 0;
@@ -521,7 +521,7 @@ void lynx2_sound_device::sound_stream_update(sound_stream &stream, stream_sample
v = m_audio[channel].reg.output;
if (!(m_master_enable & (0x10 << channel)))
{
- if (m_attenuation_enable & (0x10 << channel))
+ if (m_attenuation_enable & (0x10 << channel))
*left += v * (m_audio[channel].attenuation >> 4);
else
*left += v * 15;
diff --git a/src/mess/audio/lynx.h b/src/mess/audio/lynx.h
index 5ef44cef5f4..583c6ec75d4 100644
--- a/src/mess/audio/lynx.h
+++ b/src/mess/audio/lynx.h
@@ -66,11 +66,11 @@ class lynx2_sound_device : public lynx_sound_device
{
public:
lynx2_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
-
+
protected:
// device-level overrides
virtual void device_start();
-
+
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
};
diff --git a/src/mess/audio/wswan.c b/src/mess/audio/wswan.c
index 37a7f60cdc7..a44d6279818 100644
--- a/src/mess/audio/wswan.c
+++ b/src/mess/audio/wswan.c
@@ -81,7 +81,7 @@ void wswan_sound_device::device_start()
save_item(NAME(m_audio1.vol_right));
save_item(NAME(m_audio1.on));
save_item(NAME(m_audio1.signal));
-
+
save_item(NAME(m_audio2.freq));
save_item(NAME(m_audio2.period));
save_item(NAME(m_audio2.pos));
@@ -89,7 +89,7 @@ void wswan_sound_device::device_start()
save_item(NAME(m_audio2.vol_right));
save_item(NAME(m_audio2.on));
save_item(NAME(m_audio2.signal));
-
+
save_item(NAME(m_audio3.freq));
save_item(NAME(m_audio3.period));
save_item(NAME(m_audio3.pos));
@@ -97,7 +97,7 @@ void wswan_sound_device::device_start()
save_item(NAME(m_audio3.vol_right));
save_item(NAME(m_audio3.on));
save_item(NAME(m_audio3.signal));
-
+
save_item(NAME(m_audio4.freq));
save_item(NAME(m_audio4.period));
save_item(NAME(m_audio4.pos));
diff --git a/src/mess/drivers/a7800.c b/src/mess/drivers/a7800.c
index f40c1e1be0a..db69ae22df7 100644
--- a/src/mess/drivers/a7800.c
+++ b/src/mess/drivers/a7800.c
@@ -44,7 +44,7 @@
2013/04/07 Robert Tuccitto Address map locations for the XBOARD
added.
- 2013/05/01 Robert Tuccitto Red and Blue miscalculated proportions
+ 2013/05/01 Robert Tuccitto Red and Blue miscalculated proportions
fixed.
***************************************************************************/
diff --git a/src/mess/drivers/aim65.c b/src/mess/drivers/aim65.c
index e09f935cb0c..8eb10084eea 100644
--- a/src/mess/drivers/aim65.c
+++ b/src/mess/drivers/aim65.c
@@ -274,18 +274,18 @@ DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart )
UINT32 size;
UINT8 *temp_copy;
const struct aim_cart_range *aim_cart = &aim_cart_table[0], *this_cart;
-
+
/* First, determine where this cart has to be loaded */
while (aim_cart->tag)
{
if (strcmp(aim_cart->tag, image.device().tag()) == 0)
break;
-
+
aim_cart++;
}
-
+
this_cart = aim_cart;
-
+
if (!this_cart->tag)
{
astring errmsg;
@@ -293,19 +293,19 @@ DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart )
image.seterror(IMAGE_ERROR_UNSPECIFIED, errmsg.cstr());
return IMAGE_INIT_FAIL;
}
-
+
if (image.software_entry() == NULL)
{
size = image.length();
temp_copy = auto_alloc_array(machine(), UINT8, size);
-
+
if (size > 0x1000)
{
image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
auto_free(machine(), temp_copy);
return IMAGE_INIT_FAIL;
}
-
+
if (image.fread(temp_copy, size) != size)
{
image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file");
@@ -318,8 +318,8 @@ DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart )
if (image.get_software_region(this_cart->tag + 1) == NULL)
{
astring errmsg;
- errmsg.printf("Attempted to load file with wrong extension\nCartslot '%s' only accepts files with '.%s' extension",
- this_cart->tag, this_cart->tag + 1);
+ errmsg.printf("Attempted to load file with wrong extension\nCartslot '%s' only accepts files with '.%s' extension",
+ this_cart->tag, this_cart->tag + 1);
image.seterror(IMAGE_ERROR_UNSPECIFIED, errmsg.cstr());
return IMAGE_INIT_FAIL;
}
@@ -330,9 +330,9 @@ DEVICE_IMAGE_LOAD_MEMBER( aim65_state, aim65_cart )
}
memcpy(memregion("maincpu")->base() + this_cart->offset, temp_copy, size);
-
+
auto_free(machine(), temp_copy);
-
+
return IMAGE_INIT_PASS;
}
diff --git a/src/mess/drivers/apollo.c b/src/mess/drivers/apollo.c
index d66a5826344..f049622ea2a 100644
--- a/src/mess/drivers/apollo.c
+++ b/src/mess/drivers/apollo.c
@@ -808,8 +808,8 @@ static ADDRESS_MAP_START(dsp3500_map, AS_PROGRAM, 32, apollo_state )
// AM_RANGE(0x05d800, 0x05dc07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_mcr_r, apollo_mcr_w, 0xffffffff)
// AM_RANGE(0xfa0000, 0xfdffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_mgm_r, apollo_mgm_w, 0xffffffff)
//
-// AM_RANGE(0x05e800, 0x05ec07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_ccr_r, apollo_ccr_w, 0xffffffff)
-// AM_RANGE(0x0a0000, 0x0bffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_cgm_r, apollo_cgm_w, 0xffffffff)
+// AM_RANGE(0x05e800, 0x05ec07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_ccr_r, apollo_ccr_w, 0xffffffff)
+// AM_RANGE(0x0a0000, 0x0bffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_cgm_r, apollo_cgm_w, 0xffffffff)
AM_RANGE(ATBUS_IO_BASE, ATBUS_IO_END) AM_READWRITE16(apollo_atbus_io_r, apollo_atbus_io_w, 0xffffffff)
@@ -891,8 +891,8 @@ static ADDRESS_MAP_START(dsp3000_map, AS_PROGRAM, 32, apollo_state )
// AM_RANGE(0x05d800, 0x05dc07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_mcr_r, apollo_mcr_w, 0xffffffff)
// AM_RANGE(0xfa0000, 0xfdffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_mgm_r, apollo_mgm_w, 0xffffffff)
//
-// AM_RANGE(0x05e800, 0x05ec07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_ccr_r, apollo_ccr_w, 0xffffffff)
-// AM_RANGE(0x0a0000, 0x0bffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_cgm_r, apollo_cgm_w, 0xffffffff)
+// AM_RANGE(0x05e800, 0x05ec07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_ccr_r, apollo_ccr_w, 0xffffffff)
+// AM_RANGE(0x0a0000, 0x0bffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_cgm_r, apollo_cgm_w, 0xffffffff)
AM_RANGE(ATBUS_IO_BASE, ATBUS_IO_END) AM_READWRITE16(apollo_atbus_io_r, apollo_atbus_io_w, 0xffffffff)
@@ -994,8 +994,8 @@ static ADDRESS_MAP_START(dsp5500_map, AS_PROGRAM, 32, apollo_state )
// AM_RANGE(0x05d800, 0x05dc07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_mcr_r, apollo_mcr_w, 0xffffffff)
// AM_RANGE(0xfa0000, 0xfdffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_mgm_r, apollo_mgm_w, 0xffffffff)
//
-// AM_RANGE(0x05e800, 0x05ec07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_ccr_r, apollo_ccr_w, 0xffffffff)
-// AM_RANGE(0x0a0000, 0x0bffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_cgm_r, apollo_cgm_w, 0xffffffff)
+// AM_RANGE(0x05e800, 0x05ec07) AM_DEVREADWRITE8_LEGACY(APOLLO_SCREEN_TAG, apollo_ccr_r, apollo_ccr_w, 0xffffffff)
+// AM_RANGE(0x0a0000, 0x0bffff) AM_DEVREADWRITE16_LEGACY(APOLLO_SCREEN_TAG, apollo_cgm_r, apollo_cgm_w, 0xffffffff)
AM_RANGE(ATBUS_IO_BASE, ATBUS_IO_END) AM_READWRITE16(apollo_atbus_io_r, apollo_atbus_io_w, 0xffffffff)
diff --git a/src/mess/drivers/applix.c b/src/mess/drivers/applix.c
index faee500e141..62b242a8e8d 100644
--- a/src/mess/drivers/applix.c
+++ b/src/mess/drivers/applix.c
@@ -241,7 +241,6 @@ static MC6845_UPDATE_ROW( applix_update_row )
for (x = 0; x < x_count; x++)
{
-
if (BIT(state->m_pa, 3))
// 640 x 200 x 4of16 mode
{
diff --git a/src/mess/drivers/d6800.c b/src/mess/drivers/d6800.c
index 48787943f3a..b6088a133c8 100644
--- a/src/mess/drivers/d6800.c
+++ b/src/mess/drivers/d6800.c
@@ -287,10 +287,10 @@ READ8_MEMBER( d6800_state::d6800_cassette_r )
WRITE8_MEMBER( d6800_state::d6800_cassette_w )
{
/*
- A NE556 runs at either 1200 or 2400 Hz, depending on the state of bit 0.
- This output drives the speaker and the output signal to the cassette player.
- Bit 6 enables the speaker. Also the speaker is silenced when cassette operations
- are in progress (DMA/CB2 line low).
+ A NE556 runs at either 1200 or 2400 Hz, depending on the state of bit 0.
+ This output drives the speaker and the output signal to the cassette player.
+ Bit 6 enables the speaker. Also the speaker is silenced when cassette operations
+ are in progress (DMA/CB2 line low).
*/
m_beeper->set_frequency(BIT(data, 0) ? 2400 : 1200);
@@ -307,7 +307,7 @@ READ8_MEMBER( d6800_state::d6800_keyboard_r )
*/
UINT8 data = m_io_x0->read() & m_io_x1->read() & m_io_x2->read() & m_io_x3->read()
- & m_io_y0->read() & m_io_y1->read() & m_io_y2->read() & m_io_y3->read();
+ & m_io_y0->read() & m_io_y1->read() & m_io_y2->read() & m_io_y3->read();
return data;
}
diff --git a/src/mess/drivers/esq1.c b/src/mess/drivers/esq1.c
index 74a3dbb6a4c..23dff5bbdc4 100644
--- a/src/mess/drivers/esq1.c
+++ b/src/mess/drivers/esq1.c
@@ -170,8 +170,8 @@ NOTES:
Note that this may be incorrect, maybe to sum of squares should be
constant, the half-point should be at -3dB and the linearity in dB
space.
-
-
+
+
***************************************************************************/
#include "emu.h"
@@ -188,7 +188,7 @@ NOTES:
#define WD1772_TAG "wd1772"
class esq1_filters : public device_t,
- public device_sound_interface
+ public device_sound_interface
{
public:
// construction/destruction
@@ -225,7 +225,7 @@ static const device_type ESQ1_FILTERS = &device_creator<esq1_filters>;
esq1_filters::esq1_filters(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, ESQ1_FILTERS, "ESQ1 Filters stage", tag, owner, clock, "esq1-filters", __FILE__),
- device_sound_interface(mconfig, *this)
+ device_sound_interface(mconfig, *this)
{
}
@@ -278,11 +278,11 @@ void esq1_filters::recalc_filter(filter &f)
double g = 6060*exp(vfc/28.5);
double zc = g/tan(g/2/44100);
-/* if(f.vfc) {
- double ff = g/(2*M_PI);
- double fzc = 2*M_PI*ff/tan(M_PI*ff/44100);
- fprintf(stderr, "%02x f=%f zc=%f zc1=%f\n", f.vfc, g/(2*M_PI), zc, fzc);
- }*/
+/* if(f.vfc) {
+ double ff = g/(2*M_PI);
+ double fzc = 2*M_PI*ff/tan(M_PI*ff/44100);
+ fprintf(stderr, "%02x f=%f zc=%f zc1=%f\n", f.vfc, g/(2*M_PI), zc, fzc);
+ }*/
double gzc = zc/g;
double gzc2 = gzc*gzc;
@@ -302,10 +302,10 @@ void esq1_filters::recalc_filter(filter &f)
f.b[3] = 4*(r1 - 2*gzc + 2*gzc3 - gzc4);
f.b[4] = r1 - 4*gzc + 6*gzc2 - 4*gzc3 + gzc4;
-/* if(f.vfc != 0)
- for(int i=0; i<5; i++)
- printf("a%d=%f\nb%d=%f\n",
- i, f.a[i], i, f.b[i]);*/
+/* if(f.vfc != 0)
+ for(int i=0; i<5; i++)
+ printf("a%d=%f\nb%d=%f\n",
+ i, f.a[i], i, f.b[i]);*/
// Amplification stage
double vca = f.vca*(5.0/255.0);
@@ -336,15 +336,15 @@ void esq1_filters::device_start()
void esq1_filters::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
-/* if(0) {
- for(int i=0; i<8; i++)
- fprintf(stderr, " [%02x %02x %02x %02x]",
- filters[i].vca,
- filters[i].vpan,
- filters[i].vq,
- filters[i].vfc);
- fprintf(stderr, "\n");
- }*/
+/* if(0) {
+ for(int i=0; i<8; i++)
+ fprintf(stderr, " [%02x %02x %02x %02x]",
+ filters[i].vca,
+ filters[i].vpan,
+ filters[i].vq,
+ filters[i].vfc);
+ fprintf(stderr, "\n");
+ }*/
for(int i=0; i<samples; i++) {
double l=0, r=0;
@@ -365,11 +365,11 @@ void esq1_filters::sound_stream_update(sound_stream &stream, stream_sample_t **i
static double maxl = 0;
if(l > maxl) {
maxl = l;
-// fprintf(stderr, "%f\n", maxl);
+// fprintf(stderr, "%f\n", maxl);
}
-// l *= 6553;
-// r *= 6553;
+// l *= 6553;
+// r *= 6553;
l *= 2;
r *= 2;
outputs[0][i] = l < -32768 ? -32768 : l > 32767 ? 32767 : int(l);
@@ -532,7 +532,7 @@ ADDRESS_MAP_END
WRITE_LINE_MEMBER(esq1_state::duart_irq_handler)
{
- m_maincpu->set_input_line(M6809_IRQ_LINE, state);
+ m_maincpu->set_input_line(M6809_IRQ_LINE, state);
};
READ8_MEMBER(esq1_state::duart_input)
@@ -555,31 +555,31 @@ WRITE8_MEMBER(esq1_state::duart_output)
// MIDI send
WRITE_LINE_MEMBER(esq1_state::duart_tx_a)
{
- m_mdout->tx(state);
+ m_mdout->tx(state);
}
WRITE_LINE_MEMBER(esq1_state::duart_tx_b)
{
- m_panel->rx_w(state);
+ m_panel->rx_w(state);
}
void esq1_state::send_through_panel(UINT8 data)
{
- m_panel->xmit_char(data);
+ m_panel->xmit_char(data);
}
INPUT_CHANGED_MEMBER(esq1_state::key_stroke)
{
- if (oldval == 0 && newval == 1)
- {
- send_through_panel((UINT8)(FPTR)param);
- send_through_panel((UINT8)(FPTR)0x00);
- }
- else if (oldval == 1 && newval == 0)
- {
- send_through_panel((UINT8)(FPTR)param&0x7f);
- send_through_panel((UINT8)(FPTR)0x00);
- }
+ if (oldval == 0 && newval == 1)
+ {
+ send_through_panel((UINT8)(FPTR)param);
+ send_through_panel((UINT8)(FPTR)0x00);
+ }
+ else if (oldval == 1 && newval == 0)
+ {
+ send_through_panel((UINT8)(FPTR)param&0x7f);
+ send_through_panel((UINT8)(FPTR)0x00);
+ }
}
static SLOT_INTERFACE_START(midiin_slot)
@@ -707,7 +707,7 @@ ROM_END
ROM_START( esqm )
ROM_REGION(0x10000, "osrom", 0)
- ROM_LOAD( "1355500157_d640_esq-m_oshi.u14", 0x8000, 0x008000, CRC(ea6a7bae) SHA1(2830f8c52dc443b4ca469dc190b33e2ff15b78e1) )
+ ROM_LOAD( "1355500157_d640_esq-m_oshi.u14", 0x8000, 0x008000, CRC(ea6a7bae) SHA1(2830f8c52dc443b4ca469dc190b33e2ff15b78e1) )
ROM_REGION(0x20000, "es5503", 0)
ROM_LOAD( "esq1wavlo.bin", 0x0000, 0x8000, CRC(4d04ac87) SHA1(867b51229b0a82c886bf3b216aa8893748236d8b) )
@@ -718,4 +718,3 @@ ROM_END
CONS( 1986, esq1, 0 , 0, esq1, esq1, driver_device, 0, "Ensoniq", "ESQ-1", GAME_NOT_WORKING )
CONS( 1986, esqm, esq1, 0, esq1, esq1, driver_device, 0, "Ensoniq", "ESQ-M", GAME_NOT_WORKING )
CONS( 1988, sq80, 0, 0, sq80, esq1, driver_device, 0, "Ensoniq", "SQ-80", GAME_NOT_WORKING )
-
diff --git a/src/mess/drivers/horizon.c b/src/mess/drivers/horizon.c
index f4ddb2498a0..92aa0c3faec 100644
--- a/src/mess/drivers/horizon.c
+++ b/src/mess/drivers/horizon.c
@@ -8,25 +8,25 @@
succesfully loaded. The memory range EA00-EB40 appears to be
used by devices, particularly the FDC.
- http://www.hartetechnologies.com/manuals/Northstar/
+ http://www.hartetechnologies.com/manuals/Northstar/
****************************************************************************/
/*
- TODO:
+ TODO:
- - connect to S-100 bus
- - USARTs
- - parallel I/O
- - motherboard ports
- - RTC
- - RAM boards
- - floppy boards
- - floating point board
- - SOROC IQ 120 CRT terminal
- - NEC 5530-2 SPINWRITER printer
- - Anadex DP-8000 printer
+ - connect to S-100 bus
+ - USARTs
+ - parallel I/O
+ - motherboard ports
+ - RTC
+ - RAM boards
+ - floppy boards
+ - floating point board
+ - SOROC IQ 120 CRT terminal
+ - NEC 5530-2 SPINWRITER printer
+ - Anadex DP-8000 printer
*/
@@ -38,20 +38,20 @@
#include "machine/s100_nsmdsa.h"
#include "machine/s100_nsmdsad.h"
-#define Z80_TAG "z80"
-#define I8251_L_TAG "3a"
-#define I8251_R_TAG "4a"
-#define RS232_A_TAG "rs232a"
-#define RS232_B_TAG "rs232b"
+#define Z80_TAG "z80"
+#define I8251_L_TAG "3a"
+#define I8251_R_TAG "4a"
+#define RS232_A_TAG "rs232a"
+#define RS232_B_TAG "rs232b"
class horizon_state : public driver_device
{
public:
horizon_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag),
- m_maincpu(*this, Z80_TAG),
- m_usart_l(*this, I8251_L_TAG),
- m_usart_r(*this, I8251_L_TAG)
+ m_maincpu(*this, Z80_TAG),
+ m_usart_l(*this, I8251_L_TAG),
+ m_usart_r(*this, I8251_L_TAG)
{ }
required_device<cpu_device> m_maincpu;
diff --git a/src/mess/drivers/ie15.c b/src/mess/drivers/ie15.c
index 29b9550dfcb..49d832ad9cc 100644
--- a/src/mess/drivers/ie15.c
+++ b/src/mess/drivers/ie15.c
@@ -6,9 +6,9 @@
29/06/2012 Skeleton driver.
- A serial (RS232 or current loop) green-screen terminal, mostly VT52 compatible
- (no Hold Screen mode and no graphics character set, but has Cyrillic characters).
- The top line is a status line.
+ A serial (RS232 or current loop) green-screen terminal, mostly VT52 compatible
+ (no Hold Screen mode and no graphics character set, but has Cyrillic characters).
+ The top line is a status line.
****************************************************************************/
@@ -18,19 +18,19 @@
#include "machine/keyboard.h"
#include "sound/beep.h"
-#define SCREEN_PAGE (80*48)
+#define SCREEN_PAGE (80*48)
-#define IE_1 0x80
-#define IE_KB_ACK 1
+#define IE_1 0x80
+#define IE_KB_ACK 1
-#define IE15_TOTAL_HORZ 1000
-#define IE15_TOTAL_VERT 28*11
+#define IE15_TOTAL_HORZ 1000
+#define IE15_TOTAL_VERT 28*11
-#define IE15_DISP_HORZ 800
-#define IE15_DISP_VERT 25*11
+#define IE15_DISP_HORZ 800
+#define IE15_DISP_VERT 25*11
-#define IE15_HORZ_START 100
-#define IE15_VERT_START 2*11
+#define IE15_HORZ_START 100
+#define IE15_VERT_START 2*11
#define VERBOSE_DBG 1 /* general debug messages */
@@ -50,7 +50,7 @@
#define LOOPBACK (0)
#endif
-#define BITBANGER_TAG "bitbanger"
+#define BITBANGER_TAG "bitbanger"
class ie15_state : public driver_device
{
@@ -296,9 +296,9 @@ READ8_MEMBER( ie15_state::serial_r ) {
}
/*
- m_serial_rx_buffer incoming bits.
- m_serial_rx_bits number of bits in _buffer.
- m_serial_rx_data complete byte, ready to be read by host, or 0 if no data.
+ m_serial_rx_buffer incoming bits.
+ m_serial_rx_bits number of bits in _buffer.
+ m_serial_rx_data complete byte, ready to be read by host, or 0 if no data.
*/
WRITE_LINE_MEMBER( ie15_state::serial_rx_callback )
@@ -333,7 +333,7 @@ WRITE_LINE_MEMBER( ie15_state::serial_rx_callback )
// overflow
break;
}
- DBG_LOG(2,"serial",("r %d bits %02d->%02d buffer %02X data %02X\n",
+ DBG_LOG(2,"serial",("r %d bits %02d->%02d buffer %02X data %02X\n",
state, tmp, m_serial_rx_bits, m_serial_rx_buffer, m_serial_rx_data));
}
@@ -380,13 +380,13 @@ READ8_MEMBER( ie15_state::flag_r ) {
switch (offset)
{
- case 0: // hsync pulse (not hblank)
+ case 0: // hsync pulse (not hblank)
ret = machine().primary_screen->hpos() < IE15_HORZ_START;
break;
- case 1: // marker scanline
+ case 1: // marker scanline
ret = (machine().primary_screen->vpos() % 11) > 7;
break;
- case 2: // vblank
+ case 2: // vblank
ret = !machine().primary_screen->vblank();
break;
case 4:
@@ -436,22 +436,22 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START(ie15_io, AS_IO, 8, ie15_state)
ADDRESS_MAP_UNMAP_HIGH
- AM_RANGE(000, 000) AM_READ(mem_r) AM_WRITE(mem_w) // 00h W: memory request, R: memory data [6.1.2.2]
- AM_RANGE(001, 001) AM_READ(serial_rx_ready_r) AM_WRITENOP // 01h W: memory latch [6.1.2.2]
- AM_RANGE(002, 002) AM_WRITE(mem_addr_hi_w) // 02h W: memory address high [6.1.2.2]
- AM_RANGE(003, 003) AM_WRITE(mem_addr_lo_w) // 03h W: memory address low [6.1.2.2]
- AM_RANGE(004, 004) AM_WRITE(mem_addr_inc_w) // 04h W: memory address counter + [6.1.2.2]
- AM_RANGE(005, 005) AM_WRITE(mem_addr_dec_w) // 05h W: memory address counter - [6.1.2.2]
- AM_RANGE(006, 006) AM_READ(serial_r) AM_WRITE(serial_w) // 06h W: serial port data [6.1.5.4]
+ AM_RANGE(000, 000) AM_READ(mem_r) AM_WRITE(mem_w) // 00h W: memory request, R: memory data [6.1.2.2]
+ AM_RANGE(001, 001) AM_READ(serial_rx_ready_r) AM_WRITENOP // 01h W: memory latch [6.1.2.2]
+ AM_RANGE(002, 002) AM_WRITE(mem_addr_hi_w) // 02h W: memory address high [6.1.2.2]
+ AM_RANGE(003, 003) AM_WRITE(mem_addr_lo_w) // 03h W: memory address low [6.1.2.2]
+ AM_RANGE(004, 004) AM_WRITE(mem_addr_inc_w) // 04h W: memory address counter + [6.1.2.2]
+ AM_RANGE(005, 005) AM_WRITE(mem_addr_dec_w) // 05h W: memory address counter - [6.1.2.2]
+ AM_RANGE(006, 006) AM_READ(serial_r) AM_WRITE(serial_w) // 06h W: serial port data [6.1.5.4]
// port 7 is handled in cpu core
- AM_RANGE(010, 010) AM_READ(serial_tx_ready_r) AM_WRITE(beep_w) // 08h W: speaker control [6.1.5.4]
- AM_RANGE(011, 011) AM_READ(kb_r) // 09h R: keyboard data [6.1.5.2]
- AM_RANGE(012, 012) AM_READ(kb_s_red_r) // 0Ah I: keyboard mode "RED" [6.1.5.2]
- AM_RANGE(013, 013) AM_READ(kb_ready_r) // 0Bh R: keyboard data ready [6.1.5.2]
- AM_RANGE(014, 014) AM_READ(kb_s_sdv_r) AM_WRITENOP // 0Ch W: serial port speed [6.1.3.1], R: keyboard mode "SDV" [6.1.5.2]
- AM_RANGE(015, 015) AM_READ(kb_s_dk_r) AM_WRITE(kb_ready_w) // 0Dh I: keyboard mode "DK" [6.1.5.2]
- AM_RANGE(016, 016) AM_READ(kb_s_dupl_r) // 0Eh I: keyboard mode "DUPL" [6.1.5.2]
- AM_RANGE(017, 017) AM_READ(kb_s_lin_r) // 0Fh I: keyboard mode "LIN" [6.1.5.2]
+ AM_RANGE(010, 010) AM_READ(serial_tx_ready_r) AM_WRITE(beep_w) // 08h W: speaker control [6.1.5.4]
+ AM_RANGE(011, 011) AM_READ(kb_r) // 09h R: keyboard data [6.1.5.2]
+ AM_RANGE(012, 012) AM_READ(kb_s_red_r) // 0Ah I: keyboard mode "RED" [6.1.5.2]
+ AM_RANGE(013, 013) AM_READ(kb_ready_r) // 0Bh R: keyboard data ready [6.1.5.2]
+ AM_RANGE(014, 014) AM_READ(kb_s_sdv_r) AM_WRITENOP // 0Ch W: serial port speed [6.1.3.1], R: keyboard mode "SDV" [6.1.5.2]
+ AM_RANGE(015, 015) AM_READ(kb_s_dk_r) AM_WRITE(kb_ready_w) // 0Dh I: keyboard mode "DK" [6.1.5.2]
+ AM_RANGE(016, 016) AM_READ(kb_s_dupl_r) // 0Eh I: keyboard mode "DUPL" [6.1.5.2]
+ AM_RANGE(017, 017) AM_READ(kb_s_lin_r) // 0Fh I: keyboard mode "LIN" [6.1.5.2]
// simulation of flag registers
AM_RANGE(020, 027) AM_READ(flag_r) AM_WRITE(flag_w)
ADDRESS_MAP_END
@@ -531,12 +531,12 @@ UINT32 ie15_state::draw_scanline(UINT16 *p, UINT16 offset, UINT8 scanline, UINT8
gfx = m_p_chargen[chr | ra];
/*
- Cursor is a character with only 3 scan lines, and is
- not shown if flag 1 is not active on this scan line.
- It always blinks if shown.
+ Cursor is a character with only 3 scan lines, and is
+ not shown if flag 1 is not active on this scan line.
+ It always blinks if shown.
- Control characters blink if RED mode is on and they
- are not on status line; else they are blanked out.
+ Control characters blink if RED mode is on and they
+ are not on status line; else they are blanked out.
*/
if (scanline > 7 && (!m_cursor || blink))
@@ -577,8 +577,8 @@ UINT32 ie15_state::draw_scanline(UINT16 *p, UINT16 offset, UINT8 scanline, UINT8
TIMER_DEVICE_CALLBACK_MEMBER(ie15_state::scanline_callback)
{
UINT16 y = machine().primary_screen->vpos();
-// DBG_LOG(2,"scanline",
-// ("addr %03x frame %lld x %04d y %03d\n", m_videoptr_2, machine().primary_screen->frame_number(), machine().primary_screen->hpos(), y));
+// DBG_LOG(2,"scanline",
+// ("addr %03x frame %lld x %04d y %03d\n", m_videoptr_2, machine().primary_screen->frame_number(), machine().primary_screen->hpos(), y));
if (y>=IE15_VERT_START) {
y -= IE15_VERT_START;
if (y < IE15_DISP_VERT) {
@@ -597,15 +597,15 @@ UINT32 ie15_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, co
/* F4 Character Displayer */
static const gfx_layout ie15_charlayout =
{
- 7, 8, /* 7x8 pixels in 10x11 cell */
- 256, /* 256 characters */
- 1, /* 1 bits per pixel */
- { 0 }, /* no bitplanes */
+ 7, 8, /* 7x8 pixels in 10x11 cell */
+ 256, /* 256 characters */
+ 1, /* 1 bits per pixel */
+ { 0 }, /* no bitplanes */
/* x offsets */
{ 0, 1, 2, 3, 4, 5, 6 },
/* y offsets */
{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
- 8*8 /* every char takes 8 bytes */
+ 8*8 /* every char takes 8 bytes */
};
static GFXDECODE_START( ie15 )
diff --git a/src/mess/drivers/microkit.c b/src/mess/drivers/microkit.c
index 00563144ba3..fb4c59c6d43 100644
--- a/src/mess/drivers/microkit.c
+++ b/src/mess/drivers/microkit.c
@@ -1,8 +1,8 @@
/*
- RCA COSMAC Microkit
+ RCA COSMAC Microkit
- http://www.vintagecomputer.net/browse_thread.cfm?id=511
+ http://www.vintagecomputer.net/browse_thread.cfm?id=511
*/
diff --git a/src/mess/drivers/ngp.c b/src/mess/drivers/ngp.c
index e6e5e8ecf8f..939450f4fdd 100644
--- a/src/mess/drivers/ngp.c
+++ b/src/mess/drivers/ngp.c
@@ -677,7 +677,7 @@ void ngp_state::machine_start()
m_seconds_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ngp_state::ngp_seconds_callback),this));
m_seconds_timer->adjust( attotime::from_seconds(1), 0, attotime::from_seconds(1) );
-
+
save_item(NAME(m_io_reg));
save_item(NAME(m_old_to3));
// TODO: check if these are handled correctly...
diff --git a/src/mess/drivers/pc.c b/src/mess/drivers/pc.c
index 0a78a125b04..13c092e0f2c 100644
--- a/src/mess/drivers/pc.c
+++ b/src/mess/drivers/pc.c
@@ -1419,7 +1419,7 @@ static MACHINE_CONFIG_START( mc1502, pc_state )
MCFG_FLOPPY_DRIVE_ADD("fd1", mc1502_floppies, "525qd", 0, pc_state::floppy_formats)
MCFG_SOFTWARE_LIST_ADD("flop_list","mc1502_flop")
-// MCFG_SOFTWARE_LIST_ADD("cass_list","mc1502_cass")
+// MCFG_SOFTWARE_LIST_ADD("cass_list","mc1502_cass")
/* internal ram */
MCFG_RAM_ADD(RAM_TAG)
@@ -2169,7 +2169,7 @@ ROM_START( ec1845 )
ROMX_LOAD( "184505.bin", 0xfe001, 0x0800, CRC(c807e3f5) SHA1(08117e449f0d04f96041cff8d34893f500f3760d), ROM_SKIP(1))
ROMX_LOAD( "184506.bin", 0xff000, 0x0800, CRC(24f5c27c) SHA1(7822dd7f715ef00ccf6d8408be8bbfe01c2eba20), ROM_SKIP(1))
ROMX_LOAD( "184507.bin", 0xff001, 0x0800, CRC(75122203) SHA1(7b0fbdf1315230633e39574ac7360163bc7361e1), ROM_SKIP(1))
- ROM_REGION(0x2000,"gfx1", ROMREGION_ERASE00)
+ ROM_REGION(0x2000,"gfx1", ROMREGION_ERASE00)
ROM_END
ROM_START( asst128 )
diff --git a/src/mess/drivers/pet.c b/src/mess/drivers/pet.c
index a2f96f94895..065285b0052 100644
--- a/src/mess/drivers/pet.c
+++ b/src/mess/drivers/pet.c
@@ -462,7 +462,7 @@ WRITE8_MEMBER( cbm8296_state::write )
if (!endra)
{
//logerror("%s write %04x : cswff %u cs9 %u csa %u csio %u cse %u cskb %u fa12 %u casena1 %u endra %u noscreen %u casena2 %u fa15 %u\n",machine().describe_context(),offset,cswff,cs9,csa,csio,cse,cskb,fa12,casena1,endra,noscreen,casena2,fa15);
-
+
offs_t drma = fa15 << 15 | (offset & 0x7e00) | BIT(offset, 0) << 8 | (offset & 0x1fe) >> 1;
if (!casena1)
diff --git a/src/mess/drivers/sms.c b/src/mess/drivers/sms.c
index 87635621cfb..ac20862c916 100644
--- a/src/mess/drivers/sms.c
+++ b/src/mess/drivers/sms.c
@@ -87,7 +87,7 @@ Notes: (All ICs shown)
IC6/IC7 D4168- NEC D4168 8k x8 SRAM (DIP28)
IC8 7805 - Motorola MC7805 voltage regulator (7v to 25v input, 5v output)
IC9 CXA1145 - Sony CXA1145 RGB to composite video encoder IC (DIP24)
- POWER_IN - Power input from AC/DC power pack. System requires 9VDC at 500mA. Center pin is negative and
+ POWER_IN - Power input from AC/DC power pack. System requires 9VDC at 500mA. Center pin is negative and
outer barrel is positive. Note this is opposite to regular DC power packs
RF_OUT - RF modulator with RF signal output to TV
POWER_SW - Power on/off switch
@@ -97,16 +97,16 @@ Notes: (All ICs shown)
VSync - 49.7015Hz
-Cart PCB Examples
+Cart PCB Examples
-----------------
-Note! There are many more types of PCBs & custom chip matching variations. This document
-is not meant to provide all details of every type in existence. Some games have been
+Note! There are many more types of PCBs & custom chip matching variations. This document
+is not meant to provide all details of every type in existence. Some games have been
found on different types of ROM boards with and without bankswitching hardware.
Type with no bankswitching hardware
171-5519 \ no visible difference?
-171-5519D/
+171-5519D/
|------------------|
||----------| |
|| DIP28 | |
@@ -123,8 +123,8 @@ Notes:
World Grand Prix MPR-11074
Black Belt MPR-10150
Ghost House MPR-12586
-
-
+
+
Types with bankswitching hardware
171-5713D (uses 315-5235)
@@ -142,7 +142,7 @@ Types with bankswitching hardware
|IC2 |
|------------------|
Notes:
- SDIP42 - Custom Sega bankswitch chip at location IC1. There are several different
+ SDIP42 - Custom Sega bankswitch chip at location IC1. There are several different
types of these chips with different 315-xxxx numbers
These include 315-5235 (DIP42), 315-5208 (DIP28) and 315-5365 (DIP42) and possibly others.
DIP32 - 1MBit/2MBit/4MBit mask ROM (DIP32) at location IC2
@@ -167,7 +167,7 @@ Notes:
| |
|----------------|
Notes:
- SDIP42 - Custom Sega bankswitch chip at location IC1. There are several different
+ SDIP42 - Custom Sega bankswitch chip at location IC1. There are several different
types of these chips with different 315-xxxx numbers
These include 315-5235 (DIP42), 315-5208 (DIP28) and 315-5365 (DIP42) and possibly others.
DIP40 - 2MBit/4Mbit 16-bit mask ROM (DIP40) at location IC2
@@ -175,10 +175,10 @@ Notes:
Game Name Sega ROM ID Bank Chip
-----------------------------------------
Space Harrier MPR-10410 315-5235
-
-Another ROM board 171-5497 used by Monopoly has 315-5235 DIP42 mapper chip, DIP28 mask ROM, a DIP8 chip (unknown),
+
+Another ROM board 171-5497 used by Monopoly has 315-5235 DIP42 mapper chip, DIP28 mask ROM, a DIP8 chip (unknown),
DIP28 SRAM (likely 8k) and a 3V coin battery.
-Yet another type of ROM board with unknown PCB number used by Phantasy Star has 315-5235 DIP42 mapper chip, DIP32 mask
+Yet another type of ROM board with unknown PCB number used by Phantasy Star has 315-5235 DIP42 mapper chip, DIP32 mask
ROM and DIP28 SRAM (likely 8k) and a 3V coin battery.
Unfortunatley the majority of these ROM boards, ROM types and MPR-xxxxx Sega part numbers are undocumented because they
were mostly dumped from the edge connector without being opened.
diff --git a/src/mess/drivers/softbox.c b/src/mess/drivers/softbox.c
index aed5c083622..807a2f78f8f 100644
--- a/src/mess/drivers/softbox.c
+++ b/src/mess/drivers/softbox.c
@@ -1,8 +1,8 @@
/*
- SSE SoftBox
+ SSE SoftBox
- http://mikenaberezny.com/hardware/pet-cbm/sse-softbox-z80-computer/
+ http://mikenaberezny.com/hardware/pet-cbm/sse-softbox-z80-computer/
*/
@@ -193,14 +193,14 @@ READ8_MEMBER( softbox_state::pia1_pc_r )
bit description
- PC0
- PC1
- PC2
- PC3
+ PC0
+ PC1
+ PC2
+ PC3
PC4 Corvus READY
PC5 Corvus ACTIVE
- PC6
- PC7
+ PC6
+ PC7
*/
@@ -216,11 +216,11 @@ WRITE8_MEMBER( softbox_state::pia1_pc_w )
PC0 LED "A"
PC1 LED "B"
PC2 LED "READY"
- PC3
- PC4
- PC5
- PC6
- PC7
+ PC3
+ PC4
+ PC5
+ PC6
+ PC7
*/
diff --git a/src/mess/drivers/ts802.c b/src/mess/drivers/ts802.c
index 68e5be8598a..43193e28f17 100644
--- a/src/mess/drivers/ts802.c
+++ b/src/mess/drivers/ts802.c
@@ -7,10 +7,10 @@
TODO:
- Everything - this is just a skeleton
-
+
Technical manual at:
http://bitsavers.org/pdf/televideo/TS800A_TS802_TS802H_Maintenance_Manual_1982.pdf
-
+
includes in-depth discussion of the inner workings of the WD1000 HDD controller.
****************************************************************************/
@@ -49,7 +49,7 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START(ts802_io, AS_IO, 8, ts802_state)
//ADDRESS_MAP_UNMAP_HIGH
ADDRESS_MAP_GLOBAL_MASK(0xff)
- AM_RANGE(0x00, 0x00) AM_READ(port00_r) // DIP switches
+ AM_RANGE(0x00, 0x00) AM_READ(port00_r) // DIP switches
// 04 - written once after OS boot to bank in RAM from 0000-3FFF instead of ROM. 4000-FFFF is always RAM.
// 08-0B: Z80 CTC
// 0C-0F: Z80 SIO #1
diff --git a/src/mess/includes/gb.h b/src/mess/includes/gb.h
index 3e44670c0d2..bbe8d220505 100644
--- a/src/mess/includes/gb.h
+++ b/src/mess/includes/gb.h
@@ -96,12 +96,12 @@ struct gb_lcd_t {
UINT8 *gb_vram; // Pointer to VRAM
UINT8 *gb_oam; // Pointer to OAM memory
UINT8 gb_tile_no_mod;
- UINT32 gb_chrgen_offs; // GB Character generator
- UINT32 gb_bgdtab_offs; // GB Background character table
- UINT32 gb_wndtab_offs; // GB Window character table
- UINT32 gbc_chrgen_offs; // CGB Character generator
- UINT32 gbc_bgdtab_offs; // CGB Background character table
- UINT32 gbc_wndtab_offs; // CGB Window character table
+ UINT32 gb_chrgen_offs; // GB Character generator
+ UINT32 gb_bgdtab_offs; // GB Background character table
+ UINT32 gb_wndtab_offs; // GB Window character table
+ UINT32 gbc_chrgen_offs; // CGB Character generator
+ UINT32 gbc_bgdtab_offs; // CGB Background character table
+ UINT32 gbc_wndtab_offs; // CGB Window character table
int gb_vram_bank;
};
@@ -234,7 +234,7 @@ protected:
void gb_increment_scanline();
void gb_lcd_switch_on();
inline void gb_plot_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color);
-
+
void save_gb_base();
void save_gb_video();
void save_gbc_only();
diff --git a/src/mess/includes/lynx.h b/src/mess/includes/lynx.h
index 3a5406ae3f3..31ef7b9a4bb 100644
--- a/src/mess/includes/lynx.h
+++ b/src/mess/includes/lynx.h
@@ -116,7 +116,7 @@ public:
required_shared_ptr<UINT8> m_mem_fffa;
required_device<cpu_device> m_maincpu;
required_device<lynx_sound_device> m_sound;
-
+
UINT16 m_granularity;
int m_sign_AB;
int m_sign_CD;
diff --git a/src/mess/includes/softbox.h b/src/mess/includes/softbox.h
index 3ecc1c53497..e8cc9d68757 100644
--- a/src/mess/includes/softbox.h
+++ b/src/mess/includes/softbox.h
@@ -16,18 +16,18 @@
#define I8251_TAG "i8251"
#define I8255_0_TAG "ic17"
#define I8255_1_TAG "ic16"
-#define COM8116_TAG "ic14"
-#define RS232_TAG "rs232"
+#define COM8116_TAG "ic14"
+#define RS232_TAG "rs232"
class softbox_state : public driver_device
{
public:
softbox_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag),
- m_maincpu(*this, Z80_TAG),
- m_usart(*this, I8251_TAG),
- m_dbrg(*this, COM8116_TAG),
- m_ieee(*this, IEEE488_TAG)
+ m_maincpu(*this, Z80_TAG),
+ m_usart(*this, I8251_TAG),
+ m_dbrg(*this, COM8116_TAG),
+ m_ieee(*this, IEEE488_TAG)
{ }
required_device<cpu_device> m_maincpu;
diff --git a/src/mess/machine/apollo.c b/src/mess/machine/apollo.c
index 704be74a5c7..f26b6e61186 100644
--- a/src/mess/machine/apollo.c
+++ b/src/mess/machine/apollo.c
@@ -97,7 +97,7 @@ INPUT_PORTS_START( apollo_config )
PORT_CONFSETTING(APOLLO_CONF_8_PLANES, "8-Plane Color")
PORT_CONFSETTING(APOLLO_CONF_4_PLANES, "4-Plane Color")
PORT_CONFSETTING(APOLLO_CONF_MONO_15I, "15\" Monochrome")
-// PORT_CONFSETTING(APOLLO_CONF_MONO_19I, "19\" Monochrome")
+// PORT_CONFSETTING(APOLLO_CONF_MONO_19I, "19\" Monochrome")
PORT_CONFNAME(APOLLO_CONF_GERMAN_KBD, 0x00, "German Keyboard")
PORT_CONFSETTING(0x00, DEF_STR ( Off ) )
diff --git a/src/mess/machine/gb.c b/src/mess/machine/gb.c
index 687297b9eca..45df99d4b57 100644
--- a/src/mess/machine/gb.c
+++ b/src/mess/machine/gb.c
@@ -134,7 +134,7 @@ void gb_state::save_gbc_only()
}
void gb_state::save_sgb_only()
-{
+{
save_item(NAME(m_sgb_pal_data));
save_item(NAME(m_sgb_pal));
save_item(NAME(m_sgb_tile_map));
@@ -194,7 +194,7 @@ MACHINE_START_MEMBER(gb_state,gbpocket)
/* Allocate the serial timer, and disable it */
m_gb_serial_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_state::gb_serial_timer_proc),this));
m_gb_serial_timer->enable( 0 );
-
+
save_gb_base();
gb_video_start(GB_VIDEO_MGB);
}
@@ -231,12 +231,12 @@ MACHINE_START_MEMBER(gb_state,sgb)
MACHINE_RESET_MEMBER(gb_state,gb)
{
gb_init();
-
+
gb_video_reset(GB_VIDEO_DMG);
-
+
/* Enable BIOS rom */
m_bios_disable = 0;
-
+
m_divcount = 0x0004;
}
@@ -276,21 +276,21 @@ MACHINE_RESET_MEMBER(gb_state,gbc)
MACHINE_RESET_MEMBER(gb_state,sgb)
{
gb_init();
-
+
gb_video_reset(GB_VIDEO_SGB);
-
+
gb_init_regs();
-
-
+
+
/* Enable BIOS rom */
m_bios_disable = 0;
-
+
memset(m_sgb_tile_data, 0, 0x2000);
-
+
m_sgb_window_mask = 0;
memset(m_sgb_pal_map, 0, sizeof(m_sgb_pal_map));
memset(m_sgb_atf_data, 0, sizeof(m_sgb_atf_data));
-
+
m_divcount = 0x0004;
}
@@ -1072,7 +1072,7 @@ MACHINE_START_MEMBER(megaduck_state,megaduck)
/* Allocate the serial timer, and disable it */
m_gb_serial_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_state::gb_serial_timer_proc),this));
m_gb_serial_timer->enable( 0 );
-
+
save_gb_base();
gb_video_start(GB_VIDEO_DMG);
}
diff --git a/src/mess/machine/lynx.c b/src/mess/machine/lynx.c
index ea536791cf1..8334f171230 100644
--- a/src/mess/machine/lynx.c
+++ b/src/mess/machine/lynx.c
@@ -558,7 +558,7 @@ void lynx_state::lynx_blit_lines()
m_blitter.height_accumulator += m_blitter.height;
for (int j = 0; j < (m_blitter.height_accumulator >> 8); j++, y += ydir)
- {
+ {
if (y >= 0 && y < 102)
{
if (m_blitter.use_rle)
@@ -729,7 +729,7 @@ void lynx_state::lynx_blitter()
m_blitter.mode = m_blitter.spr_ctl0 & 0x07;
m_blitter.use_rle = m_blitter.spr_ctl1 & 0x80 ? 0 : 1;
m_blitter.line_color = (m_blitter.spr_ctl0 >> 6) & 0x03;
-
+
m_blitter.sprite_collide = !(m_blitter.spr_coll & 0x20);
m_blitter.spritenr = m_blitter.spr_coll & 0x0f;
m_blitter.fred = 0;
@@ -1986,7 +1986,7 @@ void lynx_state::machine_start()
save_item(NAME(m_uart.received));
save_item(NAME(m_uart.sending));
save_item(NAME(m_uart.buffer_loaded));
-
+
machine().save().register_postload(save_prepost_delegate(FUNC(lynx_state::lynx_postload), this));
membank("bank3")->configure_entry(0, memregion("maincpu")->base() + 0x0000);
diff --git a/src/mess/machine/md_stm95.h b/src/mess/machine/md_stm95.h
index 6bd0a07c1a7..a67a0d82aff 100644
--- a/src/mess/machine/md_stm95.h
+++ b/src/mess/machine/md_stm95.h
@@ -46,7 +46,7 @@ protected:
int stream_pos;
int stream_data;
int eeprom_addr;
-
+
running_machine& m_machine;
};
diff --git a/src/mess/machine/nes_bootleg.c b/src/mess/machine/nes_bootleg.c
index 6916240c468..652127e8fb4 100644
--- a/src/mess/machine/nes_bootleg.c
+++ b/src/mess/machine/nes_bootleg.c
@@ -430,7 +430,7 @@ void nes_lh53_device::device_start()
common_start();
irq_timer = timer_alloc(TIMER_IRQ);
irq_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1));
-
+
save_item(NAME(m_irq_enable));
save_item(NAME(m_irq_count));
save_item(NAME(m_reg));
@@ -439,10 +439,10 @@ void nes_lh53_device::device_start()
void nes_lh53_device::pcb_reset()
{
chr8(0, CHRRAM);
-
+
prg8_89(0xc);
- prg8_ab(0xd); // last 2K are overlayed by WRAM
- prg8_cd(0xe); // first 6K are overlayed by WRAM
+ prg8_ab(0xd); // last 2K are overlayed by WRAM
+ prg8_cd(0xe); // first 6K are overlayed by WRAM
prg8_ef(0xf);
m_reg = 0;
m_irq_count = 0;
@@ -1305,18 +1305,18 @@ WRITE8_MEMBER(nes_lh10_device::write_h)
}
/*-------------------------------------------------
-
+
UNL-LH53
-
+
Games: Nazo no Murasamejou (FDS conversion)
-
- This PCB maps WRAM (w/battery) in 0xb800-0xd7ff and
+
+ This PCB maps WRAM (w/battery) in 0xb800-0xd7ff and
PRG in 0x6000-0x7fff
iNES:
-
+
In MESS: Preliminar Support only.
-
+
-------------------------------------------------*/
void nes_lh53_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
@@ -1344,20 +1344,20 @@ READ8_MEMBER(nes_lh53_device::read_m)
READ8_MEMBER(nes_lh53_device::read_h)
{
LOG_MMC(("lh53 read_h, offset: %04x\n", offset));
-
+
if (offset >= 0x3800 && offset < 0x5800)
return m_battery[offset & 0x1fff];
-
+
return hi_access_rom(offset);
}
WRITE8_MEMBER(nes_lh53_device::write_h)
{
LOG_MMC(("lh53 write_h, offset: %04x, data: %02x\n", offset, data));
-
+
if (offset >= 0x3800 && offset < 0x5800)
m_battery[offset & 0x1fff] = data;
-
+
else
{
switch (offset & 0x7000)
diff --git a/src/mess/machine/nes_bootleg.h b/src/mess/machine/nes_bootleg.h
index da87dfa8b77..13a41d684a8 100644
--- a/src/mess/machine/nes_bootleg.h
+++ b/src/mess/machine/nes_bootleg.h
@@ -327,7 +327,7 @@ class nes_lh53_device : public nes_nrom_device
public:
// construction/destruction
nes_lh53_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
-
+
// device-level overrides
virtual void device_start();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
@@ -335,14 +335,14 @@ public:
virtual DECLARE_READ8_MEMBER(read_h);
virtual DECLARE_WRITE8_MEMBER(write_m) {}
virtual DECLARE_WRITE8_MEMBER(write_h);
-
+
virtual void pcb_reset();
-
+
private:
UINT16 m_irq_count;
int m_irq_enable;
UINT8 m_reg;
-
+
static const device_timer_id TIMER_IRQ = 0;
emu_timer *irq_timer;
attotime timer_freq;
diff --git a/src/mess/machine/nes_kaiser.c b/src/mess/machine/nes_kaiser.c
index ed237169b65..b425fb9120e 100644
--- a/src/mess/machine/nes_kaiser.c
+++ b/src/mess/machine/nes_kaiser.c
@@ -218,9 +218,9 @@ void nes_ks7031_device::device_start()
void nes_ks7031_device::pcb_reset()
{
- prg32(0); // not really used...
+ prg32(0); // not really used...
chr8(0, CHRRAM);
-
+
m_reg[0] = 0;
m_reg[1] = 0;
m_reg[2] = 0;
@@ -525,15 +525,15 @@ WRITE8_MEMBER(nes_ks7012_device::write_h)
/*-------------------------------------------------
-
+
Kaiser Board KS7013B
-
+
Games: Highway Star FDS Conversion
-
+
iNES:
-
+
In MESS: Supported.
-
+
-------------------------------------------------*/
WRITE8_MEMBER(nes_ks7013b_device::write_m)
@@ -556,13 +556,13 @@ WRITE8_MEMBER(nes_ks7013b_device::write_h)
Games: Dracula II FDS Conversion
This board is quite weird. It handles 2K PRG chunks
- and the chip contains chunks in reverse order, so
+ and the chip contains chunks in reverse order, so
that the first 2K are actually loaded at the top
of the 0x8000-0xffff region. Main bank is fixed, while
the 8K mapped at 0x6000-0x7fff varies with reg writes.
TODO: understand how SRAM is handled...
-
+
iNES:
In MESS: Supported.
@@ -571,7 +571,7 @@ WRITE8_MEMBER(nes_ks7013b_device::write_h)
READ8_MEMBER(nes_ks7031_device::read_m)
{
-// LOG_MMC(("ks7031 read_m, offset: %04x\n", offset));
+// LOG_MMC(("ks7031 read_m, offset: %04x\n", offset));
return m_prg[(m_reg[(offset >> 11) & 3] * 0x0800) + (offset & 0x7ff)];
}
diff --git a/src/mess/machine/nes_kaiser.h b/src/mess/machine/nes_kaiser.h
index 374fee9c833..07f6f0707ab 100644
--- a/src/mess/machine/nes_kaiser.h
+++ b/src/mess/machine/nes_kaiser.h
@@ -154,15 +154,15 @@ class nes_ks7031_device : public nes_nrom_device
public:
// construction/destruction
nes_ks7031_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
-
+
// device-level overrides
virtual void device_start();
virtual DECLARE_READ8_MEMBER(read_m);
virtual DECLARE_READ8_MEMBER(read_h);
virtual DECLARE_WRITE8_MEMBER(write_h);
-
+
virtual void pcb_reset();
-
+
private:
UINT8 m_reg[4];
};
diff --git a/src/mess/machine/nes_mmc3_clones.c b/src/mess/machine/nes_mmc3_clones.c
index 9b57cfb9816..13a788d586b 100644
--- a/src/mess/machine/nes_mmc3_clones.c
+++ b/src/mess/machine/nes_mmc3_clones.c
@@ -167,7 +167,7 @@ nes_sachen_shero_device::nes_sachen_shero_device(const machine_config &mconfig,
}
//nes_a9746_device::nes_a9746_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
-// : nes_txrom_device(mconfig, NES_A9746, "NES Cart A-9746 PCB", tag, owner, clock, "nes_bmc_a9746", __FILE__)
+// : nes_txrom_device(mconfig, NES_A9746, "NES Cart A-9746 PCB", tag, owner, clock, "nes_bmc_a9746", __FILE__)
//{
//}
@@ -2498,16 +2498,16 @@ WRITE8_MEMBER(nes_pjoy84_device::write_m)
#ifdef UNUSED_FUNCTION
/*-------------------------------------------------
-
+
UNL-A9746
-
-
+
+
MMC3 clone
-
-
+
+
Preliminary emulation based on Cah4e3's code
No dump is available (yet) for this.
-
+
-------------------------------------------------*/
void nes_a9746_device::device_start()
@@ -2519,7 +2519,7 @@ void nes_a9746_device::device_start()
void nes_a9746_device::pcb_reset()
{
m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
-
+
m_reg[0] = 0;
m_reg[1] = 0;
m_reg[2] = 0;
@@ -2529,7 +2529,7 @@ void nes_a9746_device::pcb_reset()
void nes_a9746_device::update_banks(UINT8 value)
{
UINT8 bank = BITSWAP8(value & 0x3c,7,6,0,1,2,3,4,5);
-
+
switch (m_reg[0])
{
case 0x26: prg8_89(bank); break;
@@ -2537,7 +2537,7 @@ void nes_a9746_device::update_banks(UINT8 value)
case 0x24: prg8_cd(bank); break;
case 0x23: prg8_ef(bank); break;
}
-
+
switch (m_reg[1])
{
case 0x08: case 0x0a: case 0x0c: case 0x0e:
@@ -2559,7 +2559,7 @@ void nes_a9746_device::update_banks(UINT8 value)
WRITE8_MEMBER(nes_a9746_device::write_h)
{
LOG_MMC(("unl_a9746 write_h, offset: %04x, data: %02x\n", offset, data));
-
+
switch (offset & 0x6003)
{
case 0x0000:
@@ -2573,18 +2573,17 @@ WRITE8_MEMBER(nes_a9746_device::write_h)
m_reg[0] = data;
m_reg[1] = 0;
break;
-
+
case 0x0003:
case 0x2000:
case 0x2001:
case 0x2002:
case 0x2003:
break;
-
+
default:
txrom_write(space, offset, data, mem_mask);
break;
}
}
#endif
-
diff --git a/src/mess/machine/nes_slot.c b/src/mess/machine/nes_slot.c
index bf93f3fdbfd..89881d07d92 100644
--- a/src/mess/machine/nes_slot.c
+++ b/src/mess/machine/nes_slot.c
@@ -768,7 +768,7 @@ void device_nes_cart_interface::pcb_start(running_machine &machine, UINT8 *ciram
if (m_vram_size)
state_save_register_item_pointer(machine, "NES_CART", NULL, 0, m_vram, m_vram_size);
if (m_battery_size)
- state_save_register_item_pointer(machine, "NES_CART", NULL, 0, m_battery, m_battery_size);
+ state_save_register_item_pointer(machine, "NES_CART", NULL, 0, m_battery, m_battery_size);
}
void device_nes_cart_interface::pcb_reg_postload(running_machine &machine)
diff --git a/src/mess/machine/nes_slot.h b/src/mess/machine/nes_slot.h
index b5a5049ec0b..0fe9e24ea60 100644
--- a/src/mess/machine/nes_slot.h
+++ b/src/mess/machine/nes_slot.h
@@ -107,7 +107,7 @@ enum
OPENCORP_DAOU306, HES_BOARD, SVISION16_BOARD, RUMBLESTATION_BOARD, JYCOMPANY_A, JYCOMPANY_B, JYCOMPANY_C,
MAGICSERIES_MD, KASING_BOARD, FUTUREMEDIA_BOARD, FUKUTAKE_BOARD, SOMARI_SL12,
HENGG_SRICH, HENGG_XHZS, HENGG_SHJY3, SUBOR_TYPE0, SUBOR_TYPE1,
- KAISER_KS7058, KAISER_KS7032, KAISER_KS7022, KAISER_KS7017,
+ KAISER_KS7058, KAISER_KS7032, KAISER_KS7022, KAISER_KS7017,
KAISER_KS7012, KAISER_KS7013B, KAISER_KS202, KAISER_KS7031,
CNE_DECATHLON, CNE_FSB, CNE_SHLZ, CONY_BOARD, YOKO_BOARD,
RCM_GS2015, RCM_GS2004, RCM_GS2013, RCM_TF9IN1, RCM_3DBLOCK,
diff --git a/src/mess/machine/pc.c b/src/mess/machine/pc.c
index cbbe5891bec..2cc69ebf736 100644
--- a/src/mess/machine/pc.c
+++ b/src/mess/machine/pc.c
@@ -56,7 +56,7 @@
#define DBG_LOG(N,M,A) \
do { \
- if(VERBOSE_DBG>=N) \
+ if(VERBOSE_DBG>=N) \
{ \
if( M ) \
logerror("%11.6f at %s: %-24s",machine().time().as_double(),machine().describe_context(),(char*)M ); \
diff --git a/src/mess/machine/pc_joy_sw.c b/src/mess/machine/pc_joy_sw.c
index 256834f3bdf..9ebd173d513 100644
--- a/src/mess/machine/pc_joy_sw.c
+++ b/src/mess/machine/pc_joy_sw.c
@@ -173,5 +173,3 @@ ioport_constructor pc_mssw_pad_device::device_input_ports() const
{
return INPUT_PORTS_NAME( sidewinder_pad );
}
-
-
diff --git a/src/mess/machine/psxcard.c b/src/mess/machine/psxcard.c
index a952d247c60..18b4c1e4ebb 100644
--- a/src/mess/machine/psxcard.c
+++ b/src/mess/machine/psxcard.c
@@ -54,18 +54,18 @@ void psxcard_device::device_start()
m_disabled = false;
// save state registrations
- save_item(NAME(pkt));
- save_item(NAME(pkt_ptr));
- save_item(NAME(pkt_sz));
- save_item(NAME(cmd));
- save_item(NAME(addr));
- save_item(NAME(state));
- save_item(NAME(m_disabled));
- save_item(NAME(m_odata));
- save_item(NAME(m_idata));
- save_item(NAME(m_bit));
- save_item(NAME(m_count));
- save_item(NAME(m_pad));
+ save_item(NAME(pkt));
+ save_item(NAME(pkt_ptr));
+ save_item(NAME(pkt_sz));
+ save_item(NAME(cmd));
+ save_item(NAME(addr));
+ save_item(NAME(state));
+ save_item(NAME(m_disabled));
+ save_item(NAME(m_odata));
+ save_item(NAME(m_idata));
+ save_item(NAME(m_bit));
+ save_item(NAME(m_count));
+ save_item(NAME(m_pad));
}
void psxcard_device::device_reset()
diff --git a/src/mess/machine/psxcd.c b/src/mess/machine/psxcd.c
index 7c4cc5b108d..cefce2e7497 100644
--- a/src/mess/machine/psxcd.c
+++ b/src/mess/machine/psxcd.c
@@ -1219,4 +1219,3 @@ int psxcd_device::add_system_event(int type, UINT64 t, void *ptr)
fatalerror("psxcd: out of timers\n");
return 0;
}
-
diff --git a/src/mess/machine/psxmultitap.h b/src/mess/machine/psxmultitap.h
index ca696c58376..35ec57098dc 100644
--- a/src/mess/machine/psxmultitap.h
+++ b/src/mess/machine/psxmultitap.h
@@ -5,7 +5,7 @@
SLOT_INTERFACE_EXTERN(psx_controllers_nomulti);
-class psx_multitap_device : public device_t,
+class psx_multitap_device : public device_t,
public device_psx_controller_interface
{
public:
diff --git a/src/mess/machine/s100_nsmdsa.h b/src/mess/machine/s100_nsmdsa.h
index fc9e7f79b08..d47ef5c4720 100644
--- a/src/mess/machine/s100_nsmdsa.h
+++ b/src/mess/machine/s100_nsmdsa.h
@@ -25,7 +25,7 @@
// ======================> s100_mds_a_device
class s100_mds_a_device : public device_t,
- public device_s100_card_interface
+ public device_s100_card_interface
{
public:
// construction/destruction
diff --git a/src/mess/machine/s100_nsmdsad.h b/src/mess/machine/s100_nsmdsad.h
index 8dfa900d768..098a6dd6010 100644
--- a/src/mess/machine/s100_nsmdsad.h
+++ b/src/mess/machine/s100_nsmdsad.h
@@ -25,7 +25,7 @@
// ======================> s100_mds_ad_device
class s100_mds_ad_device : public device_t,
- public device_s100_card_interface
+ public device_s100_card_interface
{
public:
// construction/destruction
diff --git a/src/mess/machine/s100_wunderbus.c b/src/mess/machine/s100_wunderbus.c
index 5b1305ccad4..85859307b28 100644
--- a/src/mess/machine/s100_wunderbus.c
+++ b/src/mess/machine/s100_wunderbus.c
@@ -19,9 +19,9 @@
#define INS8250_1_TAG "6d"
#define INS8250_2_TAG "5d"
#define INS8250_3_TAG "4d"
-#define RS232_A_TAG "rs232a"
-#define RS232_B_TAG "rs232b"
-#define RS232_C_TAG "rs232c"
+#define RS232_A_TAG "rs232a"
+#define RS232_B_TAG "rs232b"
+#define RS232_C_TAG "rs232c"
#define UPD1990C_TAG "12a"
diff --git a/src/mess/machine/sms.c b/src/mess/machine/sms.c
index 3933f1bc6c9..8755a622b31 100644
--- a/src/mess/machine/sms.c
+++ b/src/mess/machine/sms.c
@@ -330,7 +330,7 @@ int sms_state::lgun_bright_aim_area( emu_timer *timer, int lgun_x, int lgun_y )
/* Caculate distance in x of the radius, relative to beam's y distance.
First try some shortcuts. */
switch (dy)
- {
+ {
case LGUN_RADIUS:
dx_radius = 0;
break;
diff --git a/src/mess/machine/ti99/speech8.h b/src/mess/machine/ti99/speech8.h
index 51cd2b99a65..6f4537ac4e2 100644
--- a/src/mess/machine/ti99/speech8.h
+++ b/src/mess/machine/ti99/speech8.h
@@ -54,11 +54,11 @@ protected:
private:
tms5220_device *m_vsp;
-// UINT8 *m_speechrom; // pointer to speech ROM data
-// int m_load_pointer; // which 4-bit nibble will be affected by load address
-// int m_rombits_count; // current bit position in ROM
-// UINT32 m_sprom_address; // 18 bit pointer in ROM
-// UINT32 m_sprom_length; // length of data pointed by speechrom_data, from 0 to 2^18
+// UINT8 *m_speechrom; // pointer to speech ROM data
+// int m_load_pointer; // which 4-bit nibble will be affected by load address
+// int m_rombits_count; // current bit position in ROM
+// UINT32 m_sprom_address; // 18 bit pointer in ROM
+// UINT32 m_sprom_length; // length of data pointed by speechrom_data, from 0 to 2^18
// Ready line to the CPU
devcb_resolved_write_line m_ready;
diff --git a/src/mess/machine/wswan.c b/src/mess/machine/wswan.c
index 1bbbf4fe567..5643547c85d 100644
--- a/src/mess/machine/wswan.c
+++ b/src/mess/machine/wswan.c
@@ -201,7 +201,7 @@ void wswan_state::wswan_setup_bios()
void wswan_state::wswan_setup_banks()
{
- static const char *rom_bank_tags[14] = { "rom1", "rom2", "rom3", "rom4", "rom5", "rom6", "rom7",
+ static const char *rom_bank_tags[14] = { "rom1", "rom2", "rom3", "rom4", "rom5", "rom6", "rom7",
"rom8", "rom9", "rom10", "rom11", "rom12", "rom13", "rom14" };
for (int i = 0; i < 14; i++)
m_rom_bank[i] = membank(rom_bank_tags[i]);
@@ -214,7 +214,7 @@ void wswan_state::wswan_register_save()
save_item(NAME(m_bios_disabled));
save_item(NAME(m_rotate));
save_item(NAME(m_bank_base));
-
+
save_item(NAME(m_vdp.layer_bg_enable));
save_item(NAME(m_vdp.layer_fg_enable));
save_item(NAME(m_vdp.sprites_enable));
@@ -262,7 +262,7 @@ void wswan_state::wswan_register_save()
save_item(NAME(m_eeprom.size));
if (m_eeprom.size)
save_pointer(NAME(m_eeprom.data), m_eeprom.size);
-
+
save_item(NAME(m_rtc.present));
save_item(NAME(m_rtc.setting));
save_item(NAME(m_rtc.year));
@@ -273,7 +273,7 @@ void wswan_state::wswan_register_save()
save_item(NAME(m_rtc.minute));
save_item(NAME(m_rtc.second));
save_item(NAME(m_rtc.index));
-
+
save_item(NAME(m_sound_dma.source));
save_item(NAME(m_sound_dma.size));
save_item(NAME(m_sound_dma.enable));
diff --git a/src/mess/video/a7800.c b/src/mess/video/a7800.c
index 9c47501fa92..b2d1fc5ae9b 100644
--- a/src/mess/video/a7800.c
+++ b/src/mess/video/a7800.c
@@ -7,8 +7,8 @@
TODO:
precise DMA cycle stealing
- 2013-05-08 huygens rewrite to emulate line ram buffers (mostly fixes Kung-Fu Master
- Started DMA cycle stealing implementation
+ 2013-05-08 huygens rewrite to emulate line ram buffers (mostly fixes Kung-Fu Master
+ Started DMA cycle stealing implementation
2003-06-23 ericball Kangaroo mode & 320 mode & other stuff
@@ -47,13 +47,13 @@ void a7800_state::video_start()
{
m_maria_palette[i]=0;
}
-
+
for(i=0; i<2; i++)
{
for(j=0; j<160; j++)
m_line_ram[i][j] = 0;
}
-
+
m_active_buffer = 0;
m_maria_write_mode=0;
@@ -199,7 +199,7 @@ void a7800_state::maria_draw_scanline()
}
}
m_maincpu->eat_cycles(maria_cycles/4); // Maria clock rate is 4 times that of CPU
-
+
// draw line buffer to screen
m_active_buffer = !m_active_buffer; // switch buffers
UINT16 *scanline;
@@ -250,7 +250,7 @@ TIMER_DEVICE_CALLBACK_MEMBER(a7800_state::a7800_interrupt)
machine().scheduler().trigger( TRIGGER_HSYNC );
m_maria_wsync = 0;
}
-
+
int frame_scanline = m_screen->vpos() % ( m_lines + 1 );
if (frame_scanline == 16)
m_maria_vblank = 0x00;
@@ -304,7 +304,7 @@ TIMER_CALLBACK_MEMBER(a7800_state::a7800_maria_startdma)
m_maria_offset--;
}
}
-
+
if( m_maria_nmi )
{
m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
@@ -343,7 +343,7 @@ READ8_MEMBER(a7800_state::a7800_MARIA_r)
WRITE8_MEMBER(a7800_state::a7800_MARIA_w)
{
int i;
-
+
if ((offset & 3) != 0)
m_maria_palette[offset] = data;
diff --git a/src/mess/video/apollo.c b/src/mess/video/apollo.c
index 9f7290fd086..8325e6813ad 100644
--- a/src/mess/video/apollo.c
+++ b/src/mess/video/apollo.c
@@ -43,15 +43,15 @@
#define SR_BLANK 0x80
#define SR_V_BLANK 0x40
#define SR_H_SYNC 0x20
-#define SR_DONE 0x20 // 4- and 8-plane color
+#define SR_DONE 0x20 // 4- and 8-plane color
#define SR_R_M_W 0x10
#define SR_ALT 0x08
#define SR_V_SYNC 0x04
-#define SR_SYNC 0x04 // 4- and 8-plane color
+#define SR_SYNC 0x04 // 4- and 8-plane color
#define SR_H_CK 0x02
#define SR_V_DATA 0x01
-#define SR_V_FLAG 0x01 // 4-plane color
-#define SR_LUT_OK 0x01 // 8-plane color
+#define SR_V_FLAG 0x01 // 4-plane color
+#define SR_LUT_OK 0x01 // 8-plane color
// control register 0
#define CR0_MODE(a) ((a) >> 5)
#define CR0_MODE_0 0
@@ -64,9 +64,9 @@
// control register 1
#define CR1_INV 0x80
-#define CR1_AD_BIT 0x80 // 4- and 8-plane color
+#define CR1_AD_BIT 0x80 // 4- and 8-plane color
#define CR1_DADDR_16 0x40
-#define CR1_DV_CK 0x40 // 4- and 8-plane color
+#define CR1_DV_CK 0x40 // 4- and 8-plane color
#define CR1_DH_CK 0x20
#define CR1_ROP_EN 0x10
#define CR1_RESET 0x08
@@ -96,7 +96,7 @@
#define LUT_C0 0x01
#define LUT_C1_C0(a) ((a)& (LUT_C1|LUT_C0))
-#define LUT_FIFO_SIZE 1024
+#define LUT_FIFO_SIZE 1024
//**************************************************************************
// class apollo_graphics
@@ -235,9 +235,9 @@ private:
running_machine *m_machine;
};
- //**************************************************************************
- // class LUT Fifo
- //**************************************************************************
+ //**************************************************************************
+ // class LUT Fifo
+ //**************************************************************************
class apollo_graphics::lut_fifo
{
@@ -490,7 +490,7 @@ UINT8 apollo_graphics::bt458::read(UINT8 c10)
break;
}
-// MLOG1(("reading Bt458 data=%02x cs=%d", m_data, c10));
+// MLOG1(("reading Bt458 data=%02x cs=%d", m_data, c10));
return data;
}
@@ -629,7 +629,7 @@ void apollo_graphics::device_reset()
memset(m_color_lookup_table, 0, sizeof(m_color_lookup_table));
memset(m_image_memory, 0, m_image_memory_size * 2);
- // register_vblank_callback(this);
+ // register_vblank_callback(this);
}
void apollo_graphics::device_reset_mono19i()
@@ -912,7 +912,7 @@ void apollo_graphics::increment_p_clock()
// FIXME: ok for DEX Test 5 6 17 20 - nok for 19
// Note: for dn3500_19i DEX Test 17 18 20 will fail !!!!
// Note: must NOT reset m_data_clock in increment_p_clock !
-// int pixel_addr = m_data_clock * 32;
+// int pixel_addr = m_data_clock * 32;
UINT16 pixel = m_image_memory[pixel_addr / 16] & (0x8000 >> (pixel_addr % 16));
diff --git a/src/mess/video/gb.c b/src/mess/video/gb.c
index 8f50a2ab262..042d487c766 100644
--- a/src/mess/video/gb.c
+++ b/src/mess/video/gb.c
@@ -1204,14 +1204,14 @@ void gb_state::save_gb_video()
save_item(NAME(m_lcd.window_lines_drawn));
save_item(NAME(m_lcd.gb_vid_regs));
save_item(NAME(m_lcd.bg_zbuf));
-
+
save_item(NAME(m_lcd.cgb_bpal));
save_item(NAME(m_lcd.cgb_spal));
-
+
save_item(NAME(m_lcd.gb_bpal));
save_item(NAME(m_lcd.gb_spal0));
save_item(NAME(m_lcd.gb_spal1));
-
+
save_item(NAME(m_lcd.current_line));
save_item(NAME(m_lcd.cmp_line));
save_item(NAME(m_lcd.sprCount));
@@ -1244,7 +1244,7 @@ void gb_state::save_gb_video()
save_item(NAME(m_lcd.gbc_chrgen_offs));
save_item(NAME(m_lcd.gbc_bgdtab_offs));
save_item(NAME(m_lcd.gbc_wndtab_offs));
-
+
save_item(NAME(m_lcd.layer[0].enabled));
save_item(NAME(m_lcd.layer[0].xindex));
save_item(NAME(m_lcd.layer[0].xshift));
@@ -1269,8 +1269,8 @@ void gb_state::gb_video_start( int mode )
save_pointer(NAME(m_lcd.gb_vram), vram_size);
save_pointer(NAME(m_lcd.gb_oam), 0x100);
- save_gb_video();
-
+ save_gb_video();
+
if (mode == GB_VIDEO_CGB)
{
m_lcd.lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_state::gbc_lcd_timer_proc),this));
@@ -1281,11 +1281,11 @@ void gb_state::gb_video_start( int mode )
m_lcd.lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_state::gb_lcd_timer_proc),this));
machine().save().register_postload(save_prepost_delegate(FUNC(gb_state::gb_videoptr_restore), this));
}
-
+
switch (mode)
{
case GB_VIDEO_DMG:
- memcpy(m_lcd.gb_oam, dmg_oam_fingerprint, 0x100);
+ memcpy(m_lcd.gb_oam, dmg_oam_fingerprint, 0x100);
break;
case GB_VIDEO_MGB:
/* Initialize part of VRAM. This code must be deleted when we have added the bios dump */
@@ -1298,7 +1298,7 @@ void gb_state::gb_video_start( int mode )
memcpy(m_lcd.gb_oam, mgb_oam_fingerprint, 0x100);
break;
case GB_VIDEO_SGB:
- break;
+ break;
case GB_VIDEO_CGB:
memcpy(m_lcd.gb_oam, cgb_oam_fingerprint, 0x100);
break;
@@ -1317,7 +1317,7 @@ void gb_state::gb_video_reset( int mode )
address_space &space = m_maincpu->space(AS_PROGRAM);
m_lcd.window_lines_drawn = 0;
-
+
m_lcd.current_line = 0;
m_lcd.cmp_line = 0;
m_lcd.sprCount = 0;
@@ -1340,11 +1340,11 @@ void gb_state::gb_video_reset( int mode )
m_lcd.gbc_mode = 0;
m_lcd.gb_tile_no_mod = 0;
m_lcd.gb_vram_bank = 0;
-
+
m_lcd.gb_chrgen_offs = 0;
m_lcd.gb_bgdtab_offs = 0x1c00;
m_lcd.gb_wndtab_offs = 0x1c00;
-
+
memset(&m_lcd.gb_vid_regs, 0, sizeof(m_lcd.gb_vid_regs));
memset(&m_lcd.bg_zbuf, 0, sizeof(m_lcd.bg_zbuf));
memset(&m_lcd.cgb_bpal, 0, sizeof(m_lcd.cgb_bpal));
diff --git a/src/mess/video/k1ge.c b/src/mess/video/k1ge.c
index 86984e4f8a7..e0d1309c2d7 100644
--- a/src/mess/video/k1ge.c
+++ b/src/mess/video/k1ge.c
@@ -893,4 +893,3 @@ k2ge_device::k2ge_device(const machine_config &mconfig, const char *tag, device_
: k1ge_device(mconfig, K2GE, "K2GE Color Graphics + LCD", tag, owner, clock)
{
}
-
diff --git a/src/osd/sdl/debugqtdasmwindow.h b/src/osd/sdl/debugqtdasmwindow.h
index 633a6029b74..f723fad55dc 100644
--- a/src/osd/sdl/debugqtdasmwindow.h
+++ b/src/osd/sdl/debugqtdasmwindow.h
@@ -52,13 +52,13 @@ public:
m_rightBar(0)
{
}
-
+
~DasmWindowQtConfig() {}
-
+
// Settings
int m_cpu;
int m_rightBar;
-
+
void buildFromQWidget(QWidget* widget);
void applyToQWidget(QWidget* widget);
void addToXmlDataNode(xml_data_node* node) const;
diff --git a/src/osd/sdl/debugqtlogwindow.h b/src/osd/sdl/debugqtlogwindow.h
index 18fce1ea760..812da3715ad 100644
--- a/src/osd/sdl/debugqtlogwindow.h
+++ b/src/osd/sdl/debugqtlogwindow.h
@@ -35,9 +35,9 @@ public:
WindowQtConfig(WIN_TYPE_LOG)
{
}
-
+
~LogWindowQtConfig() {}
-
+
void buildFromQWidget(QWidget* widget);
void applyToQWidget(QWidget* widget);
void addToXmlDataNode(xml_data_node* node) const;
diff --git a/src/osd/sdl/debugqtmainwindow.c b/src/osd/sdl/debugqtmainwindow.c
index cc4223a3e23..fab7fddc440 100644
--- a/src/osd/sdl/debugqtmainwindow.c
+++ b/src/osd/sdl/debugqtmainwindow.c
@@ -125,7 +125,7 @@ void MainWindow::setProcessor(device_t* processor)
void MainWindow::closeEvent(QCloseEvent* event)
{
debugActQuit();
-
+
// Insure the window doesn't disappear before we get a chance to save its parameters
event->ignore();
}
diff --git a/src/osd/sdl/debugqtmainwindow.h b/src/osd/sdl/debugqtmainwindow.h
index f01ea0bb716..8d25bf60a2a 100644
--- a/src/osd/sdl/debugqtmainwindow.h
+++ b/src/osd/sdl/debugqtmainwindow.h
@@ -171,13 +171,13 @@ public:
m_rightBar(0),
m_windowState()
{}
-
+
~MainWindowQtConfig() {}
-
+
// Settings
int m_rightBar;
QByteArray m_windowState;
-
+
void buildFromQWidget(QWidget* widget);
void applyToQWidget(QWidget* widget);
void addToXmlDataNode(xml_data_node* node) const;
diff --git a/src/osd/sdl/debugqtmemorywindow.c b/src/osd/sdl/debugqtmemorywindow.c
index 29ad1e291a6..1297d787266 100644
--- a/src/osd/sdl/debugqtmemorywindow.c
+++ b/src/osd/sdl/debugqtmemorywindow.c
@@ -293,18 +293,18 @@ void DebuggerMemView::mousePressEvent(QMouseEvent* event)
address_space* addressSpace = source->space();
const int nativeDataWidth = addressSpace->data_width() / 8;
const UINT64 memValue = debug_read_memory(*addressSpace,
- addressSpace->address_to_byte(address),
- nativeDataWidth,
- true);
- const offs_t pc = source->device()->debug()->track_mem_pc_from_space_address_data(addressSpace->spacenum(),
- address,
- memValue);
+ addressSpace->address_to_byte(address),
+ nativeDataWidth,
+ true);
+ const offs_t pc = source->device()->debug()->track_mem_pc_from_space_address_data(addressSpace->spacenum(),
+ address,
+ memValue);
if (pc != (offs_t)(-1))
{
// TODO: You can specify a box that the tooltip stays alive within - might be good?
const QString addressAndPc = QString("Address %1 written at PC=%2").arg(address, 2, 16).arg(pc, 2, 16);
QToolTip::showText(QCursor::pos(), addressAndPc, NULL);
-
+
// Copy the PC into the clipboard as well
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(QString("%1").arg(pc, 2, 16));
diff --git a/src/osd/sdl/debugqtmemorywindow.h b/src/osd/sdl/debugqtmemorywindow.h
index 88ddd9f58fe..b48ea03645c 100644
--- a/src/osd/sdl/debugqtmemorywindow.h
+++ b/src/osd/sdl/debugqtmemorywindow.h
@@ -54,10 +54,10 @@ public:
DebuggerMemView(const debug_view_type& type,
running_machine* machine,
QWidget* parent=NULL)
- : DebuggerView(type, machine, parent)
+ : DebuggerView(type, machine, parent)
{}
virtual ~DebuggerMemView() {}
-
+
protected:
void mousePressEvent(QMouseEvent* event);
};
@@ -79,13 +79,13 @@ public:
}
~MemoryWindowQtConfig() {}
-
+
// Settings
int m_reverse;
int m_addressMode;
int m_chunkSize;
int m_memoryRegion;
-
+
void buildFromQWidget(QWidget* widget);
void applyToQWidget(QWidget* widget);
void addToXmlDataNode(xml_data_node* node) const;
diff --git a/src/osd/sdl/debugqtview.h b/src/osd/sdl/debugqtview.h
index fd78760d169..16ce1f48fbd 100644
--- a/src/osd/sdl/debugqtview.h
+++ b/src/osd/sdl/debugqtview.h
@@ -12,8 +12,8 @@ class DebuggerView : public QAbstractScrollArea
public:
DebuggerView(const debug_view_type& type,
- running_machine* machine,
- QWidget* parent=NULL);
+ running_machine* machine,
+ QWidget* parent=NULL);
virtual ~DebuggerView();
void paintEvent(QPaintEvent* event);
diff --git a/src/osd/sdl/debugqtwindow.h b/src/osd/sdl/debugqtwindow.h
index 63dddc6ea42..9ae0852d3a3 100644
--- a/src/osd/sdl/debugqtwindow.h
+++ b/src/osd/sdl/debugqtwindow.h
@@ -77,17 +77,17 @@ public:
m_next(NULL)
{}
virtual ~WindowQtConfig() {}
-
+
// Settings
WindowType m_type;
QPoint m_size;
QPoint m_position;
-
+
// Dues for becoming a member of a simple_list
WindowQtConfig* m_next;
WindowQtConfig* next() const { return m_next; }
-
-
+
+
virtual void buildFromQWidget(QWidget* widget);
virtual void applyToQWidget(QWidget* widget);
virtual void addToXmlDataNode(xml_data_node* node) const;
diff --git a/src/osd/windows/d3d9intf.c b/src/osd/windows/d3d9intf.c
index 3f0002b3d61..0c0a60bccb0 100644
--- a/src/osd/windows/d3d9intf.c
+++ b/src/osd/windows/d3d9intf.c
@@ -67,7 +67,6 @@ static direct3dx9_loadeffect_ptr g_load_effect = NULL;
namespace d3d
{
-
//============================================================
// PROTOTYPES
//============================================================
diff --git a/src/osd/windows/d3dcomm.h b/src/osd/windows/d3dcomm.h
index f2e8270099c..ec3ee2e97c9 100644
--- a/src/osd/windows/d3dcomm.h
+++ b/src/osd/windows/d3dcomm.h
@@ -48,7 +48,6 @@
namespace d3d
{
-
class texture_info;
class renderer;
@@ -92,35 +91,35 @@ public:
texture_manager(renderer *d3d);
~texture_manager();
- void update_textures();
+ void update_textures();
- void create_resources();
- void delete_resources();
+ void create_resources();
+ void delete_resources();
- texture_info * find_texinfo(const render_texinfo *texture, UINT32 flags);
- UINT32 texture_compute_hash(const render_texinfo *texture, UINT32 flags);
+ texture_info * find_texinfo(const render_texinfo *texture, UINT32 flags);
+ UINT32 texture_compute_hash(const render_texinfo *texture, UINT32 flags);
- texture_info * get_texlist() { return m_texlist; }
- void set_texlist(texture_info *texlist) { m_texlist = texlist; }
- bool is_dynamic_supported() { return (bool)m_dynamic_supported; }
- void set_dynamic_supported(bool dynamic_supported) { m_dynamic_supported = dynamic_supported; }
- bool is_stretch_supported() { return (bool)m_stretch_supported; }
- D3DFORMAT get_yuv_format() { return m_yuv_format; }
+ texture_info * get_texlist() { return m_texlist; }
+ void set_texlist(texture_info *texlist) { m_texlist = texlist; }
+ bool is_dynamic_supported() { return (bool)m_dynamic_supported; }
+ void set_dynamic_supported(bool dynamic_supported) { m_dynamic_supported = dynamic_supported; }
+ bool is_stretch_supported() { return (bool)m_stretch_supported; }
+ D3DFORMAT get_yuv_format() { return m_yuv_format; }
- DWORD get_texture_caps() { return m_texture_caps; }
- DWORD get_max_texture_aspect() { return m_texture_max_aspect; }
- DWORD get_max_texture_width() { return m_texture_max_width; }
- DWORD get_max_texture_height() { return m_texture_max_height; }
+ DWORD get_texture_caps() { return m_texture_caps; }
+ DWORD get_max_texture_aspect() { return m_texture_max_aspect; }
+ DWORD get_max_texture_width() { return m_texture_max_width; }
+ DWORD get_max_texture_height() { return m_texture_max_height; }
- texture_info * get_default_texture() { return m_default_texture; }
- texture_info * get_vector_texture() { return m_vector_texture; }
+ texture_info * get_default_texture() { return m_default_texture; }
+ texture_info * get_vector_texture() { return m_vector_texture; }
- renderer * get_d3d() { return m_renderer; }
+ renderer * get_d3d() { return m_renderer; }
private:
- renderer * m_renderer;
+ renderer * m_renderer;
- texture_info * m_texlist; // list of active textures
+ texture_info * m_texlist; // list of active textures
int m_dynamic_supported; // are dynamic textures supported?
int m_stretch_supported; // is StretchRect with point filtering supported?
D3DFORMAT m_yuv_format; // format to use for YUV textures
@@ -131,10 +130,10 @@ private:
DWORD m_texture_max_height; // texture maximum height
bitmap_argb32 m_vector_bitmap; // experimental: bitmap for vectors
- texture_info * m_vector_texture; // experimental: texture for vectors
+ texture_info * m_vector_texture; // experimental: texture for vectors
bitmap_rgb32 m_default_bitmap; // experimental: default bitmap
- texture_info * m_default_texture; // experimental: default texture
+ texture_info * m_default_texture; // experimental: default texture
};
@@ -145,66 +144,66 @@ public:
texture_info(texture_manager *manager, const render_texinfo *texsource, UINT32 flags);
~texture_info();
- render_texinfo & get_texinfo() { return m_texinfo; }
+ render_texinfo & get_texinfo() { return m_texinfo; }
- int get_width() { return m_rawdims.c.x; }
- int get_height() { return m_rawdims.c.y; }
- int get_xscale() { return m_xprescale; }
- int get_yscale() { return m_yprescale; }
+ int get_width() { return m_rawdims.c.x; }
+ int get_height() { return m_rawdims.c.y; }
+ int get_xscale() { return m_xprescale; }
+ int get_yscale() { return m_yprescale; }
- UINT32 get_flags() { return m_flags; }
+ UINT32 get_flags() { return m_flags; }
- void set_data(const render_texinfo *texsource, UINT32 flags);
+ void set_data(const render_texinfo *texsource, UINT32 flags);
- texture_info * get_next() { return m_next; }
- texture_info * get_prev() { return m_prev; }
+ texture_info * get_next() { return m_next; }
+ texture_info * get_prev() { return m_prev; }
- UINT32 get_hash() { return m_hash; }
+ UINT32 get_hash() { return m_hash; }
- void set_next(texture_info *next) { m_next = next; }
- void set_prev(texture_info *prev) { m_prev = prev; }
+ void set_next(texture_info *next) { m_next = next; }
+ void set_prev(texture_info *prev) { m_prev = prev; }
- bool paused() { return m_cur_frame == m_prev_frame; }
- void advance_frame() { m_prev_frame = m_cur_frame; }
- void increment_frame_count() { m_cur_frame++; }
- void mask_frame_count(int mask) { m_cur_frame %= mask; }
+ bool paused() { return m_cur_frame == m_prev_frame; }
+ void advance_frame() { m_prev_frame = m_cur_frame; }
+ void increment_frame_count() { m_cur_frame++; }
+ void mask_frame_count(int mask) { m_cur_frame %= mask; }
- int get_cur_frame() { return m_cur_frame; }
- int get_prev_frame() { return m_prev_frame; }
+ int get_cur_frame() { return m_cur_frame; }
+ int get_prev_frame() { return m_prev_frame; }
- texture * get_tex() { return m_d3dtex; }
- surface * get_surface() { return m_d3dsurface; }
- texture * get_finaltex() { return m_d3dfinaltex; }
+ texture * get_tex() { return m_d3dtex; }
+ surface * get_surface() { return m_d3dsurface; }
+ texture * get_finaltex() { return m_d3dfinaltex; }
- vec2f & get_uvstart() { return m_start; }
- vec2f & get_uvstop() { return m_stop; }
- vec2f & get_rawdims() { return m_rawdims; }
+ vec2f & get_uvstart() { return m_start; }
+ vec2f & get_uvstop() { return m_stop; }
+ vec2f & get_rawdims() { return m_rawdims; }
private:
void prescale();
void compute_size(int texwidth, int texheight);
- texture_manager * m_texture_manager; // texture manager pointer
-
- renderer * m_renderer; // renderer pointer
-
- texture_info * m_next; // next texture in the list
- texture_info * m_prev; // prev texture in the list
-
- UINT32 m_hash; // hash value for the texture
- UINT32 m_flags; // rendering flags
- render_texinfo m_texinfo; // copy of the texture info
- vec2f m_start; // beggining UV coordinates
- vec2f m_stop; // ending UV coordinates
- vec2f m_rawdims; // raw dims of the texture
- int m_type; // what type of texture are we?
- int m_xborderpix, m_yborderpix; // number of border pixels on X/Y
- int m_xprescale, m_yprescale; // X/Y prescale factor
- int m_cur_frame; // what is our current frame?
- int m_prev_frame; // what was our last frame? (used to determine pause state)
- texture * m_d3dtex; // Direct3D texture pointer
- surface * m_d3dsurface; // Direct3D offscreen plain surface pointer
- texture * m_d3dfinaltex; // Direct3D final (post-scaled) texture
+ texture_manager * m_texture_manager; // texture manager pointer
+
+ renderer * m_renderer; // renderer pointer
+
+ texture_info * m_next; // next texture in the list
+ texture_info * m_prev; // prev texture in the list
+
+ UINT32 m_hash; // hash value for the texture
+ UINT32 m_flags; // rendering flags
+ render_texinfo m_texinfo; // copy of the texture info
+ vec2f m_start; // beggining UV coordinates
+ vec2f m_stop; // ending UV coordinates
+ vec2f m_rawdims; // raw dims of the texture
+ int m_type; // what type of texture are we?
+ int m_xborderpix, m_yborderpix; // number of border pixels on X/Y
+ int m_xprescale, m_yprescale; // X/Y prescale factor
+ int m_cur_frame; // what is our current frame?
+ int m_prev_frame; // what was our last frame? (used to determine pause state)
+ texture * m_d3dtex; // Direct3D texture pointer
+ surface * m_d3dsurface; // Direct3D offscreen plain surface pointer
+ texture * m_d3dfinaltex; // Direct3D final (post-scaled) texture
int m_target_index; // Direct3D target index
};
@@ -223,18 +222,18 @@ public:
float prim_width, float prim_height);
D3DPRIMITIVETYPE get_type() { return m_type; }
- UINT32 get_count() { return m_count; }
- UINT32 get_vertcount() { return m_numverts; }
- UINT32 get_flags() { return m_flags; }
+ UINT32 get_count() { return m_count; }
+ UINT32 get_vertcount() { return m_numverts; }
+ UINT32 get_flags() { return m_flags; }
- d3d::texture_info * get_texture() { return m_texture; }
- DWORD get_modmode() { return m_modmode; }
+ d3d::texture_info * get_texture() { return m_texture; }
+ DWORD get_modmode() { return m_modmode; }
- float get_line_time() { return m_line_time; }
- float get_line_length() { return m_line_length; }
+ float get_line_time() { return m_line_time; }
+ float get_line_length() { return m_line_length; }
- float get_prim_width() { return m_prim_width; }
- float get_prim_height() { return m_prim_height; }
+ float get_prim_width() { return m_prim_width; }
+ float get_prim_height() { return m_prim_height; }
private:
@@ -243,14 +242,14 @@ private:
UINT32 m_numverts; // total number of vertices
UINT32 m_flags; // rendering flags
- texture_info * m_texture; // pointer to texture info
+ texture_info * m_texture; // pointer to texture info
DWORD m_modmode; // texture modulation mode
float m_line_time; // used by vectors
float m_line_length; // used by vectors
- float m_prim_width; // used by quads
- float m_prim_height; // used by quads
+ float m_prim_width; // used by quads
+ float m_prim_height; // used by quads
};
}; // d3d
diff --git a/src/osd/windows/d3dhlsl.c b/src/osd/windows/d3dhlsl.c
index 87522ec2808..f81b8870c26 100644
--- a/src/osd/windows/d3dhlsl.c
+++ b/src/osd/windows/d3dhlsl.c
@@ -88,7 +88,6 @@ static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *temp
namespace d3d
{
-
hlsl_options shaders::s_hlsl_presets[4] =
{
{ // 25% Shadow mask, 50% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation
@@ -2131,7 +2130,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight,
options->bloom_level6_weight, options->bloom_level7_weight };
float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight,
- options->bloom_level10_weight };
+ options->bloom_level10_weight };
(*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123);
(*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567);
(*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A);
@@ -2302,7 +2301,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight,
options->bloom_level6_weight, options->bloom_level7_weight };
float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight,
- options->bloom_level10_weight };
+ options->bloom_level10_weight };
(*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123);
(*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567);
(*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A);
@@ -3432,4 +3431,3 @@ static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *temp
file.set_openflags(origflags);
return file.open(fname);
}
-
diff --git a/src/osd/windows/d3dhlsl.h b/src/osd/windows/d3dhlsl.h
index ad08466a6a0..035f5d3b359 100644
--- a/src/osd/windows/d3dhlsl.h
+++ b/src/osd/windows/d3dhlsl.h
@@ -49,7 +49,7 @@
//============================================================
#define HLSL_VECTOR (1)
-#define CRT_BLOOM (1)
+#define CRT_BLOOM (1)
//============================================================
// TYPE DEFINITIONS
@@ -57,7 +57,6 @@
namespace d3d
{
-
class render_target;
class cache_target;
class renderer;
@@ -172,7 +171,7 @@ public:
void init_fsfx_quad(void *vertbuf);
void set_texture(texture_info *texture);
- render_target * find_render_target(texture_info *info);
+ render_target * find_render_target(texture_info *info);
void remove_render_target(texture_info *texture);
void remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
void remove_render_target(render_target *rt);
@@ -196,11 +195,11 @@ private:
bool register_texture(texture_info *texture, int width, int height, int xscale, int yscale);
- render_target* find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
- cache_target * find_cache_target(UINT32 screen_index, int width, int height);
+ render_target* find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
+ cache_target * find_cache_target(UINT32 screen_index, int width, int height);
void remove_cache_target(cache_target *cache);
- base * d3dintf; // D3D interface
+ base * d3dintf; // D3D interface
win_window_info * window; // D3D window info
bool master_enable; // overall enable flag
@@ -218,7 +217,7 @@ private:
int prescale_size_y; // prescale size y
int preset; // preset, if relevant
bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader
- texture_info * shadow_texture; // shadow mask texture for post-processing shader
+ texture_info * shadow_texture; // shadow mask texture for post-processing shader
hlsl_options * options; // current uniform state
D3DPRIMITIVETYPE vecbuf_type;
UINT32 vecbuf_index;
@@ -229,20 +228,20 @@ private:
int avi_frame; // AVI frame
attotime avi_frame_period; // AVI frame period
attotime avi_next_frame_time; // AVI next frame time
- surface * avi_copy_surface; // AVI destination surface in system memory
- texture * avi_copy_texture; // AVI destination texture in system memory
- surface * avi_final_target; // AVI upscaled surface
- texture * avi_final_texture; // AVI upscaled texture
+ surface * avi_copy_surface; // AVI destination surface in system memory
+ texture * avi_copy_texture; // AVI destination texture in system memory
+ surface * avi_final_target; // AVI upscaled surface
+ texture * avi_final_texture; // AVI upscaled texture
- surface * black_surface; // black dummy surface
- texture * black_texture; // black dummy texture
+ surface * black_surface; // black dummy surface
+ texture * black_texture; // black dummy texture
bool render_snap; // whether or not to take HLSL post-render snapshot
bool snap_rendered; // whether we just rendered our HLSL post-render shot or not
- surface * snap_copy_target; // snapshot destination surface in system memory
- texture * snap_copy_texture; // snapshot destination surface in system memory
- surface * snap_target; // snapshot upscaled surface
- texture * snap_texture; // snapshot upscaled texture
+ surface * snap_copy_target; // snapshot destination surface in system memory
+ texture * snap_copy_texture; // snapshot destination surface in system memory
+ surface * snap_target; // snapshot upscaled surface
+ texture * snap_texture; // snapshot upscaled texture
int snap_width; // snapshot width
int snap_height; // snapshot height
bool lines_pending; // whether or not we have lines to flush on the next quad
@@ -250,32 +249,32 @@ private:
bool initialized; // whether or not we're initialize
// HLSL effects
- surface * backbuffer; // pointer to our device's backbuffer
- effect * curr_effect; // pointer to the currently active effect object
- effect * default_effect; // pointer to the primary-effect object
- effect * prescale_effect; // pointer to the prescale-effect object
- effect * post_effect; // pointer to the post-effect object
- effect * pincushion_effect; // pointer to the pincushion-effect object
- effect * focus_effect; // pointer to the focus-effect object
- effect * phosphor_effect; // pointer to the phosphor-effect object
- effect * deconverge_effect; // pointer to the deconvergence-effect object
- effect * color_effect; // pointer to the color-effect object
- effect * yiq_encode_effect; // pointer to the YIQ encoder effect object
- effect * yiq_decode_effect; // pointer to the YIQ decoder effect object
+ surface * backbuffer; // pointer to our device's backbuffer
+ effect * curr_effect; // pointer to the currently active effect object
+ effect * default_effect; // pointer to the primary-effect object
+ effect * prescale_effect; // pointer to the prescale-effect object
+ effect * post_effect; // pointer to the post-effect object
+ effect * pincushion_effect; // pointer to the pincushion-effect object
+ effect * focus_effect; // pointer to the focus-effect object
+ effect * phosphor_effect; // pointer to the phosphor-effect object
+ effect * deconverge_effect; // pointer to the deconvergence-effect object
+ effect * color_effect; // pointer to the color-effect object
+ effect * yiq_encode_effect; // pointer to the YIQ encoder effect object
+ effect * yiq_decode_effect; // pointer to the YIQ decoder effect object
#if (HLSL_VECTOR || CRT_BLOOM)
- effect * bloom_effect; // pointer to the bloom composite effect
- effect * downsample_effect; // pointer to the bloom downsample effect
+ effect * bloom_effect; // pointer to the bloom composite effect
+ effect * downsample_effect; // pointer to the bloom downsample effect
#endif
#if (HLSL_VECTOR)
- effect * vector_effect; // pointer to the vector-effect object
+ effect * vector_effect; // pointer to the vector-effect object
#endif
- vertex * fsfx_vertices; // pointer to our full-screen-quad object
+ vertex * fsfx_vertices; // pointer to our full-screen-quad object
public:
- render_target * targethead;
- cache_target * cachehead;
+ render_target * targethead;
+ cache_target * cachehead;
- static hlsl_options s_hlsl_presets[4];
+ static hlsl_options s_hlsl_presets[4];
};
};
diff --git a/src/osd/windows/d3dintf.h b/src/osd/windows/d3dintf.h
index a0a68f7fea7..8b72732d025 100644
--- a/src/osd/windows/d3dintf.h
+++ b/src/osd/windows/d3dintf.h
@@ -68,7 +68,6 @@
namespace d3d
{
-
//============================================================
// TYPE DEFINITIONS
//============================================================
diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c
index 8e58163f6a2..686df150f5e 100644
--- a/src/osd/windows/drawd3d.c
+++ b/src/osd/windows/drawd3d.c
@@ -362,7 +362,6 @@ static int drawd3d_window_draw(win_window_info *window, HDC dc, int update)
namespace d3d
{
-
void renderer::set_texture(texture_info *texture)
{
if (texture != m_last_texture)
@@ -651,59 +650,59 @@ texture_info *texture_manager::find_texinfo(const render_texinfo *texinfo, UINT3
/*int checkidx = 0;
for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
{
- printf("Checking texture index %d\n", checkidx);
- UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1;
- UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1;
- UINT32 prim_screen = (UINT32)texinfo->osddata >> 1;
- UINT32 prim_page = (UINT32)texinfo->osddata & 1;
- if (test_screen != prim_screen || test_page != prim_page)
- {
- printf("No screen/page match: %d vs. %d, %d vs. %d\n", test_screen, prim_screen, test_page, prim_page);
- continue;
- }
-
- if (texture->get_hash() == hash &&
- texture->get_texinfo().base == texinfo->base &&
- texture->get_texinfo().width == texinfo->width &&
- texture->get_texinfo().height == texinfo->height &&
- ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
- {
- // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
- if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
- {
- if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
- {
- return texture;
- }
- }
- else
- {
- return texture;
- }
- }
-
- if (texture->get_hash() != hash)
- {
- printf("No hash match: %d vs. %d\n", texture->get_hash(), hash);
- }
- if (texture->get_texinfo().base != texinfo->base)
- {
- printf("No base match\n");
- }
- if (texture->get_texinfo().width != texinfo->width)
- {
- printf("No width match: %d vs. %d\n", texture->get_texinfo().width, texinfo->width);
- }
- if (texture->get_texinfo().height != texinfo->height)
- {
- printf("No height match: %d vs. %d\n", texture->get_texinfo().height, texinfo->height);
- }
- if (((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) != 0)
- {
- printf("No flag match: %08x & %08x = %08x\n", texture->get_flags(), flags, ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)));
- }
- printf("\n");
- checkidx++;
+ printf("Checking texture index %d\n", checkidx);
+ UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1;
+ UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1;
+ UINT32 prim_screen = (UINT32)texinfo->osddata >> 1;
+ UINT32 prim_page = (UINT32)texinfo->osddata & 1;
+ if (test_screen != prim_screen || test_page != prim_page)
+ {
+ printf("No screen/page match: %d vs. %d, %d vs. %d\n", test_screen, prim_screen, test_page, prim_page);
+ continue;
+ }
+
+ if (texture->get_hash() == hash &&
+ texture->get_texinfo().base == texinfo->base &&
+ texture->get_texinfo().width == texinfo->width &&
+ texture->get_texinfo().height == texinfo->height &&
+ ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
+ {
+ // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
+ if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
+ {
+ if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
+ {
+ return texture;
+ }
+ }
+ else
+ {
+ return texture;
+ }
+ }
+
+ if (texture->get_hash() != hash)
+ {
+ printf("No hash match: %d vs. %d\n", texture->get_hash(), hash);
+ }
+ if (texture->get_texinfo().base != texinfo->base)
+ {
+ printf("No base match\n");
+ }
+ if (texture->get_texinfo().width != texinfo->width)
+ {
+ printf("No width match: %d vs. %d\n", texture->get_texinfo().width, texinfo->width);
+ }
+ if (texture->get_texinfo().height != texinfo->height)
+ {
+ printf("No height match: %d vs. %d\n", texture->get_texinfo().height, texinfo->height);
+ }
+ if (((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) != 0)
+ {
+ printf("No flag match: %08x & %08x = %08x\n", texture->get_flags(), flags, ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)));
+ }
+ printf("\n");
+ checkidx++;
}
printf("\n\n\n\n");*/
@@ -733,7 +732,7 @@ texture_info *texture_manager::find_texinfo(const render_texinfo *texinfo, UINT3
texture->get_texinfo().base == texinfo->base &&
((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 &&
(texture->get_texinfo().width != texinfo->width ||
- texture->get_texinfo().height != texinfo->height))
+ texture->get_texinfo().height != texinfo->height))
{
m_renderer->get_shaders()->remove_render_target(texture);
}
@@ -1835,9 +1834,9 @@ void renderer::draw_quad(const render_primitive *prim)
}
void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
- UINT32 flags, texture_info *texture, UINT32 modmode,
- float line_time, float line_length,
- float prim_width, float prim_height)
+ UINT32 flags, texture_info *texture, UINT32 modmode,
+ float line_time, float line_length,
+ float prim_width, float prim_height)
{
init(type, count, numverts, flags, texture, modmode, prim_width, prim_height);
m_line_time = line_time;
@@ -1845,8 +1844,8 @@ void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
}
void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
- UINT32 flags, texture_info *texture, UINT32 modmode,
- float prim_width, float prim_height)
+ UINT32 flags, texture_info *texture, UINT32 modmode,
+ float prim_width, float prim_height)
{
m_type = type;
m_count = count;
@@ -1963,7 +1962,7 @@ void renderer::primitive_flush_pending()
{
// add the primitives
result = (*d3dintf->device.draw_primitive)(m_device, m_poly[polynum].get_type(), vertnum,
- m_poly[polynum].get_count());
+ m_poly[polynum].get_count());
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
}
@@ -3007,4 +3006,4 @@ bool render_target::init(renderer *d3d, base *d3dintf, int width, int height, in
return true;
}
-}; \ No newline at end of file
+};
diff --git a/src/osd/windows/drawd3d.h b/src/osd/windows/drawd3d.h
index 8cc464f090b..95d34ebb6a0 100644
--- a/src/osd/windows/drawd3d.h
+++ b/src/osd/windows/drawd3d.h
@@ -59,7 +59,6 @@
namespace d3d
{
-
class cache_target;
class render_target;
class renderer;
@@ -133,100 +132,100 @@ public:
renderer(win_window_info *window);
~renderer();
- int initialize();
+ int initialize();
- int device_create();
- int device_create_resources();
- void device_delete();
- void device_delete_resources();
+ int device_create();
+ int device_create_resources();
+ void device_delete();
+ void device_delete_resources();
- int device_verify_caps();
- int device_test_cooperative();
+ int device_verify_caps();
+ int device_test_cooperative();
- int config_adapter_mode();
- void pick_best_mode();
- int get_adapter_for_monitor();
+ int config_adapter_mode();
+ void pick_best_mode();
+ int get_adapter_for_monitor();
- int update_window_size();
+ int update_window_size();
- int pre_window_draw_check();
- void begin_frame();
- void end_frame();
+ int pre_window_draw_check();
+ void begin_frame();
+ void end_frame();
- void draw_line(const render_primitive *prim);
- void draw_quad(const render_primitive *prim);
- void batch_vector(const render_primitive *prim, float line_time);
- void batch_vectors();
+ void draw_line(const render_primitive *prim);
+ void draw_quad(const render_primitive *prim);
+ void batch_vector(const render_primitive *prim, float line_time);
+ void batch_vectors();
- vertex * mesh_alloc(int numverts);
+ vertex * mesh_alloc(int numverts);
- void update_textures();
+ void update_textures();
- void process_primitives();
- void primitive_flush_pending();
+ void process_primitives();
+ void primitive_flush_pending();
- void set_texture(texture_info *texture);
- void set_filter(int filter);
- void set_wrap(D3DTEXTUREADDRESS wrap);
- void set_modmode(DWORD modmode);
- void set_blendmode(int blendmode);
- void reset_render_states();
+ void set_texture(texture_info *texture);
+ void set_filter(int filter);
+ void set_wrap(D3DTEXTUREADDRESS wrap);
+ void set_modmode(DWORD modmode);
+ void set_blendmode(int blendmode);
+ void reset_render_states();
// Setters / getters
- int get_adapter() { return m_adapter; }
- int get_width() { return m_width; }
- int get_height() { return m_height; }
- int get_refresh() { return m_refresh; }
+ int get_adapter() { return m_adapter; }
+ int get_width() { return m_width; }
+ int get_height() { return m_height; }
+ int get_refresh() { return m_refresh; }
- win_window_info * get_window() { return m_window; }
+ win_window_info * get_window() { return m_window; }
- device * get_device() { return m_device; }
- present_parameters * get_presentation() { return &m_presentation; }
+ device * get_device() { return m_device; }
+ present_parameters * get_presentation() { return &m_presentation; }
- vertex_buffer * get_vertex_buffer() { return m_vertexbuf; }
- vertex * get_locked_buffer() { return m_lockedbuf; }
- VOID ** get_locked_buffer_ptr() { return (VOID **)&m_lockedbuf; }
- void set_locked_buffer(vertex *lockedbuf) { m_lockedbuf = lockedbuf; }
+ vertex_buffer * get_vertex_buffer() { return m_vertexbuf; }
+ vertex * get_locked_buffer() { return m_lockedbuf; }
+ VOID ** get_locked_buffer_ptr() { return (VOID **)&m_lockedbuf; }
+ void set_locked_buffer(vertex *lockedbuf) { m_lockedbuf = lockedbuf; }
- void set_restarting(bool restarting) { m_restarting = restarting; }
- bool is_mod2x_supported() { return (bool)m_mod2x_supported; }
- bool is_mod4x_supported() { return (bool)m_mod4x_supported; }
+ void set_restarting(bool restarting) { m_restarting = restarting; }
+ bool is_mod2x_supported() { return (bool)m_mod2x_supported; }
+ bool is_mod4x_supported() { return (bool)m_mod4x_supported; }
- D3DFORMAT get_screen_format() { return m_screen_format; }
+ D3DFORMAT get_screen_format() { return m_screen_format; }
D3DFORMAT get_pixel_format() { return m_pixformat; }
D3DDISPLAYMODE get_origmode() { return m_origmode; }
- UINT32 get_last_texture_flags() { return m_last_texture_flags; }
+ UINT32 get_last_texture_flags() { return m_last_texture_flags; }
- texture_manager * get_texture_manager() { return m_texture_manager; }
- texture_info * get_default_texture() { return m_texture_manager->get_default_texture(); }
- texture_info * get_vector_texture() { return m_texture_manager->get_vector_texture(); }
+ texture_manager * get_texture_manager() { return m_texture_manager; }
+ texture_info * get_default_texture() { return m_texture_manager->get_default_texture(); }
+ texture_info * get_vector_texture() { return m_texture_manager->get_vector_texture(); }
- shaders * get_shaders() { return m_shaders; }
+ shaders * get_shaders() { return m_shaders; }
private:
int m_adapter; // ordinal adapter number
- int m_width; // current width
- int m_height; // current height
+ int m_width; // current width
+ int m_height; // current height
int m_refresh; // current refresh rate
int m_create_error_count; // number of consecutive create errors
win_window_info * m_window; // current window info
- device * m_device; // pointer to the Direct3DDevice object
+ device * m_device; // pointer to the Direct3DDevice object
int m_gamma_supported; // is full screen gamma supported?
- present_parameters m_presentation; // set of presentation parameters
+ present_parameters m_presentation; // set of presentation parameters
D3DDISPLAYMODE m_origmode; // original display mode for the adapter
D3DFORMAT m_pixformat; // pixel format we are using
- vertex_buffer * m_vertexbuf; // pointer to the vertex buffer object
- vertex * m_lockedbuf; // pointer to the locked vertex buffer
+ vertex_buffer * m_vertexbuf; // pointer to the vertex buffer object
+ vertex * m_lockedbuf; // pointer to the locked vertex buffer
int m_numverts; // number of accumulated vertices
- vertex * m_vectorbatch; // pointer to the vector batch buffer
- int m_batchindex; // current index into the vector batch
+ vertex * m_vectorbatch; // pointer to the vector batch buffer
+ int m_batchindex; // current index into the vector batch
- poly_info m_poly[VERTEX_BUFFER_SIZE/3];// array to hold polygons as they are created
+ poly_info m_poly[VERTEX_BUFFER_SIZE/3];// array to hold polygons as they are created
int m_numpolys; // number of accumulated polygons
bool m_restarting; // if we're restarting
@@ -235,22 +234,22 @@ private:
int m_mod4x_supported; // is D3DTOP_MODULATE4X supported?
D3DFORMAT m_screen_format; // format to use for screen textures
- texture_info * m_last_texture; // previous texture
+ texture_info * m_last_texture; // previous texture
UINT32 m_last_texture_flags; // previous texture flags
int m_last_blendenable; // previous blendmode
int m_last_blendop; // previous blendmode
int m_last_blendsrc; // previous blendmode
int m_last_blenddst; // previous blendmode
int m_last_filter; // previous texture filter
- D3DTEXTUREADDRESS m_last_wrap; // previous wrap state
+ D3DTEXTUREADDRESS m_last_wrap; // previous wrap state
DWORD m_last_modmode; // previous texture modulation
void * m_hlsl_buf; // HLSL vertex data
- shaders * m_shaders; // HLSL interface
+ shaders * m_shaders; // HLSL interface
- texture_manager * m_texture_manager; // texture manager
+ texture_manager * m_texture_manager; // texture manager
- int m_line_count;
+ int m_line_count;
};
};
diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c
index 2c0615875c3..b57fd4782f6 100644
--- a/src/osd/windows/winmain.c
+++ b/src/osd/windows/winmain.c
@@ -398,19 +398,19 @@ const options_entry windows_options::s_option_entries[] =
{ WINOPTION_VECTOR_LENGTH_RATIO";vecsize", "4.0", OPTION_FLOAT, "Vector fade length (4.0 - vectors fade the most at and above 4 pixels, etc.)" },
/* Bloom below this line */
{ NULL, NULL, OPTION_HEADER, "BLOOM POST-PROCESSING OPTIONS" },
- { WINOPTION_VECTOR_BLOOM_SCALE, "0.3", OPTION_FLOAT, "Intensity factor for vector bloom" },
- { WINOPTION_RASTER_BLOOM_SCALE, "0.25", OPTION_FLOAT, "Intensity factor for raster bloom" },
- { WINOPTION_BLOOM_LEVEL0_WEIGHT, "1.0", OPTION_FLOAT, "Bloom level 0 (full-size target) weight" },
- { WINOPTION_BLOOM_LEVEL1_WEIGHT, "0.21", OPTION_FLOAT, "Bloom level 1 (half-size target) weight" },
- { WINOPTION_BLOOM_LEVEL2_WEIGHT, "0.19", OPTION_FLOAT, "Bloom level 2 (quarter-size target) weight" },
- { WINOPTION_BLOOM_LEVEL3_WEIGHT, "0.17", OPTION_FLOAT, "Bloom level 3 (.) weight" },
- { WINOPTION_BLOOM_LEVEL4_WEIGHT, "0.15", OPTION_FLOAT, "Bloom level 4 (.) weight" },
- { WINOPTION_BLOOM_LEVEL5_WEIGHT, "0.14", OPTION_FLOAT, "Bloom level 5 (.) weight" },
- { WINOPTION_BLOOM_LEVEL6_WEIGHT, "0.13", OPTION_FLOAT, "Bloom level 6 (.) weight" },
- { WINOPTION_BLOOM_LEVEL7_WEIGHT, "0.12", OPTION_FLOAT, "Bloom level 7 (.) weight" },
- { WINOPTION_BLOOM_LEVEL8_WEIGHT, "0.11", OPTION_FLOAT, "Bloom level 8 (.) weight" },
- { WINOPTION_BLOOM_LEVEL9_WEIGHT, "0.10", OPTION_FLOAT, "Bloom level 9 (.) weight" },
- { WINOPTION_BLOOM_LEVEL10_WEIGHT, "0.09", OPTION_FLOAT, "Bloom level 10 (1x1 target) weight" },
+ { WINOPTION_VECTOR_BLOOM_SCALE, "0.3", OPTION_FLOAT, "Intensity factor for vector bloom" },
+ { WINOPTION_RASTER_BLOOM_SCALE, "0.25", OPTION_FLOAT, "Intensity factor for raster bloom" },
+ { WINOPTION_BLOOM_LEVEL0_WEIGHT, "1.0", OPTION_FLOAT, "Bloom level 0 (full-size target) weight" },
+ { WINOPTION_BLOOM_LEVEL1_WEIGHT, "0.21", OPTION_FLOAT, "Bloom level 1 (half-size target) weight" },
+ { WINOPTION_BLOOM_LEVEL2_WEIGHT, "0.19", OPTION_FLOAT, "Bloom level 2 (quarter-size target) weight" },
+ { WINOPTION_BLOOM_LEVEL3_WEIGHT, "0.17", OPTION_FLOAT, "Bloom level 3 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL4_WEIGHT, "0.15", OPTION_FLOAT, "Bloom level 4 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL5_WEIGHT, "0.14", OPTION_FLOAT, "Bloom level 5 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL6_WEIGHT, "0.13", OPTION_FLOAT, "Bloom level 6 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL7_WEIGHT, "0.12", OPTION_FLOAT, "Bloom level 7 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL8_WEIGHT, "0.11", OPTION_FLOAT, "Bloom level 8 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL9_WEIGHT, "0.10", OPTION_FLOAT, "Bloom level 9 (.) weight" },
+ { WINOPTION_BLOOM_LEVEL10_WEIGHT, "0.09", OPTION_FLOAT, "Bloom level 10 (1x1 target) weight" },
// per-window options
{ NULL, NULL, OPTION_HEADER, "PER-WINDOW VIDEO OPTIONS" },
diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h
index 66ff631ed06..3726de0d450 100644
--- a/src/osd/windows/winmain.h
+++ b/src/osd/windows/winmain.h
@@ -133,8 +133,8 @@
#define WINOPTION_VECTOR_TIME_PERIOD "vector_time_period"
#define WINOPTION_VECTOR_LENGTH_SCALE "vector_length_scale"
#define WINOPTION_VECTOR_LENGTH_RATIO "vector_length_ratio"
-#define WINOPTION_VECTOR_BLOOM_SCALE "vector_bloom_scale"
-#define WINOPTION_RASTER_BLOOM_SCALE "raster_bloom_scale"
+#define WINOPTION_VECTOR_BLOOM_SCALE "vector_bloom_scale"
+#define WINOPTION_RASTER_BLOOM_SCALE "raster_bloom_scale"
#define WINOPTION_BLOOM_LEVEL0_WEIGHT "bloom_lvl0_weight"
#define WINOPTION_BLOOM_LEVEL1_WEIGHT "bloom_lvl1_weight"
#define WINOPTION_BLOOM_LEVEL2_WEIGHT "bloom_lvl2_weight"
diff --git a/src/tools/chdman.c b/src/tools/chdman.c
index 07c06b6544d..43c165f2c75 100644
--- a/src/tools/chdman.c
+++ b/src/tools/chdman.c
@@ -1255,7 +1255,7 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
core_fprintf(file, " PREGAP %s\n", msf_string_from_frames(tempstr, info.pregap));
core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
}
- else if ((info.pregap > 0) && (info.pgdatasize > 0))
+ else if ((info.pregap > 0) && (info.pgdatasize > 0))
{
core_fprintf(file, " INDEX 00 %s\n", msf_string_from_frames(tempstr, frameoffs));
core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs+info.pregap));
diff --git a/src/version.c b/src/version.c
index 2a70206f176..bc3c533ce95 100644
--- a/src/version.c
+++ b/src/version.c
@@ -38,4 +38,4 @@
***************************************************************************/
extern const char build_version[];
-const char build_version[] = "0.148u4 ("__DATE__")";
+const char build_version[] = "0.148u5 ("__DATE__")";