Compare commits
447 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e72ffe8af | ||
|
|
89b2d05780 | ||
|
|
bc9cea5c29 | ||
|
|
d5bc5f1368 | ||
|
|
c91229c9b9 | ||
|
|
0a93e457f7 | ||
|
|
2e8ea3f20b | ||
|
|
cf54069a36 | ||
|
|
7970391e70 | ||
|
|
f67d8a58cd | ||
|
|
dfdb3625ef | ||
|
|
fa8dba9f2f | ||
|
|
c01ec8dc8f | ||
|
|
bd1c83ca51 | ||
|
|
f8237affd2 | ||
|
|
8cc5e08479 | ||
|
|
4e9d0da3ca | ||
|
|
a8fcbd0016 | ||
|
|
d051df63df | ||
|
|
8aa528c82a | ||
|
|
0e1be48bdd | ||
|
|
3570083129 | ||
|
|
f68206261d | ||
|
|
376e4ec9ac | ||
|
|
61c0fb297d | ||
|
|
ca0b3a0ef2 | ||
|
|
5af1943160 | ||
|
|
f4d825eb43 | ||
|
|
8f75e458a0 | ||
|
|
61384921e0 | ||
|
|
a508ac4b01 | ||
|
|
7e3639367e | ||
|
|
db82ec1d2f | ||
|
|
6a46ff8910 | ||
|
|
c5108f74f8 | ||
|
|
7edd705c04 | ||
|
|
81725e2278 | ||
|
|
c54db16f84 | ||
|
|
c20577b42c | ||
|
|
428d9f2825 | ||
|
|
25d984be12 | ||
|
|
2dbb81890c | ||
|
|
50274a868f | ||
|
|
70fab05654 | ||
|
|
bd8a50bac5 | ||
|
|
3d7738a3fd | ||
|
|
d223f9e697 | ||
|
|
f03a5c11bc | ||
|
|
5a4224fded | ||
|
|
4bf91b3056 | ||
|
|
3f8cd2a2b3 | ||
|
|
78a8545b8b | ||
|
|
f4e90c31d2 | ||
|
|
a2aa1d9d77 | ||
|
|
cfcb6002d8 | ||
|
|
7f3898286c | ||
|
|
524d708130 | ||
|
|
cdca0dc4a1 | ||
|
|
5ecb58bafc | ||
|
|
49e58b59c5 | ||
|
|
d7508770f9 | ||
|
|
edead44510 | ||
|
|
c2ce97ad3e | ||
|
|
02a7774295 | ||
|
|
ee528d4356 | ||
|
|
4ad2e33198 | ||
|
|
3986490ce0 | ||
|
|
be80d16679 | ||
|
|
048174c51e | ||
|
|
4a5c1b917b | ||
|
|
0dc76480ad | ||
|
|
89df7dcc82 | ||
|
|
766ee32201 | ||
|
|
921c3d11f3 | ||
|
|
5f215c812b | ||
|
|
902e44cf26 | ||
|
|
49e3ed1416 | ||
|
|
320449821c | ||
|
|
aa512b0eb4 | ||
|
|
41ba79ea1e | ||
|
|
d42b261973 | ||
|
|
74b58de20f | ||
|
|
b5fdf331cc | ||
|
|
e6deaf9dbe | ||
|
|
bb63309662 | ||
|
|
ad291ed384 | ||
|
|
58b72e10c0 | ||
|
|
63abed3519 | ||
|
|
e03c9515e1 | ||
|
|
bf042da6a0 | ||
|
|
dbc2b7698c | ||
|
|
8212084061 | ||
|
|
38cde47ec5 | ||
|
|
86445d72de | ||
|
|
7fee1fab40 | ||
|
|
c3ac218240 | ||
|
|
97cf199254 | ||
|
|
cabcd57dfe | ||
|
|
adac28f4d7 | ||
|
|
608d86b447 | ||
|
|
6be81412b3 | ||
|
|
87bc6f9bd7 | ||
|
|
a82eb50d8c | ||
|
|
e9cae1ca15 | ||
|
|
78664a7301 | ||
|
|
31c73450f7 | ||
|
|
43473e3dcd | ||
|
|
194ae4278a | ||
|
|
60a79a8871 | ||
|
|
5ee2485fc5 | ||
|
|
74ed3adde1 | ||
|
|
a48b8bd259 | ||
|
|
b7f22b334c | ||
|
|
48daa7fa24 | ||
|
|
3fca88b2b9 | ||
|
|
a763560aa6 | ||
|
|
d307a8284c | ||
|
|
b75fe39d53 | ||
|
|
71da3c9f12 | ||
|
|
15912adc0f | ||
|
|
6c524c3a70 | ||
|
|
270bc06e99 | ||
|
|
c5b32c02a4 | ||
|
|
bce451d5f3 | ||
|
|
3124cd3a36 | ||
|
|
cc476eb7ef | ||
|
|
65208a68ce | ||
|
|
dded7cddfc | ||
|
|
0fab234b80 | ||
|
|
413b649783 | ||
|
|
82caf21987 | ||
|
|
36cec4c2ba | ||
|
|
d6711a2751 | ||
|
|
8be643d1f0 | ||
|
|
ef2f5a4cb0 | ||
|
|
342865cd61 | ||
|
|
50c1780c3b | ||
|
|
91de220b8d | ||
|
|
cdfc829893 | ||
|
|
5d5add96c8 | ||
|
|
7ed77269fb | ||
|
|
fe7c413c90 | ||
|
|
9f2696e487 | ||
|
|
bae94d0a6b | ||
|
|
4d5b86ca83 | ||
|
|
369e0bc4a1 | ||
|
|
8ed0f5f188 | ||
|
|
1a7e6a252e | ||
|
|
9a47d8a3d4 | ||
|
|
4347b17b96 | ||
|
|
529973681c | ||
|
|
6754622171 | ||
|
|
d0cd330069 | ||
|
|
675e75c591 | ||
|
|
85767a590c | ||
|
|
7a718a2537 | ||
|
|
9aea281020 | ||
|
|
04da8cbd1f | ||
|
|
cf7481e2f6 | ||
|
|
a694289ba9 | ||
|
|
6cc21aa625 | ||
|
|
a46b556690 | ||
|
|
ece2cc8ed7 | ||
|
|
40c6dc594e | ||
|
|
b59d1dabd3 | ||
|
|
4eb8a350c6 | ||
|
|
eca073d92f | ||
|
|
602d05c5ee | ||
|
|
315184d135 | ||
|
|
2408ef3317 | ||
|
|
b73df32873 | ||
|
|
166be39c8d | ||
|
|
99239d7098 | ||
|
|
87b7caf67c | ||
|
|
2d1a8a008f | ||
|
|
ada0c62e24 | ||
|
|
6740ed2219 | ||
|
|
e88e191cde | ||
|
|
e7e98746b1 | ||
|
|
49a776c9ad | ||
|
|
71d920beec | ||
|
|
db8cd726bc | ||
|
|
3192b349c9 | ||
|
|
3827af5e5c | ||
|
|
6c5ffada1f | ||
|
|
d1e9cbacb8 | ||
|
|
8b501e7138 | ||
|
|
472f866bac | ||
|
|
8ed7b6d57d | ||
|
|
a1011d6445 | ||
|
|
635bf4f0a3 | ||
|
|
c0ed99b306 | ||
|
|
dccb8d991d | ||
|
|
a59c401089 | ||
|
|
acd7a8a637 | ||
|
|
471a089bd3 | ||
|
|
f3b9b98827 | ||
|
|
27a8608eaa | ||
|
|
b39c572e70 | ||
|
|
7d675727fa | ||
|
|
b7bb3bcbdf | ||
|
|
9b2fbbeed5 | ||
|
|
d0abf8cace | ||
|
|
51dc9dc1b0 | ||
|
|
134f708957 | ||
|
|
f727cdad8d | ||
|
|
2879864592 | ||
|
|
43cfd6a831 | ||
|
|
fe71cd7948 | ||
|
|
917cb49e14 | ||
|
|
e21ccea66d | ||
|
|
19140b37c3 | ||
|
|
9d02c4b101 | ||
|
|
22af60ef0c | ||
|
|
5d10c5a3a1 | ||
|
|
165e857d99 | ||
|
|
b638171f67 | ||
|
|
d8fd99b903 | ||
|
|
20f8e6aad6 | ||
|
|
ecb4b8a61d | ||
|
|
6a6e61d427 | ||
|
|
e8e1dc3cbc | ||
|
|
019c7b79a6 | ||
|
|
b61e257fe8 | ||
|
|
54d960ebf9 | ||
|
|
9bec5aed4f | ||
|
|
768e193eb4 | ||
|
|
c376e657c2 | ||
|
|
7423a64227 | ||
|
|
44fa08ab7c | ||
|
|
c1ec9d0194 | ||
|
|
1c65ddbf24 | ||
|
|
3885ffd841 | ||
|
|
068b00d7da | ||
|
|
dfea53f000 | ||
|
|
aa2c146bb2 | ||
|
|
5508504e23 | ||
|
|
82a4f0cf4e | ||
|
|
3b5e8efa46 | ||
|
|
cd59051481 | ||
|
|
6908dd1655 | ||
|
|
f4aaa6f2ae | ||
|
|
abb0427276 | ||
|
|
2504544636 | ||
|
|
7fa431ea7f | ||
|
|
c46ac8ca03 | ||
|
|
810bf8c328 | ||
|
|
ffa1916276 | ||
|
|
12204aa47f | ||
|
|
deaaaa9364 | ||
|
|
9730ca2d50 | ||
|
|
393908e084 | ||
|
|
9fd71feb30 | ||
|
|
ce58945513 | ||
|
|
a8809711ba | ||
|
|
24c4086758 | ||
|
|
b6eef092f6 | ||
|
|
ed536b27f1 | ||
|
|
b38d570423 | ||
|
|
c5c0f5e23c | ||
|
|
a55e485723 | ||
|
|
e4de673b54 | ||
|
|
bfb539c101 | ||
|
|
5e69443e82 | ||
|
|
1de7f6464a | ||
|
|
fde92af67d | ||
|
|
cb3a39107e | ||
|
|
4dfaf65c8c | ||
|
|
c71d8cc19a | ||
|
|
1285ca0a27 | ||
|
|
ec37c40e5f | ||
|
|
4fa13b6957 | ||
|
|
3f251a864a | ||
|
|
1a8a1978ea | ||
|
|
e8bfb85874 | ||
|
|
910e904d9c | ||
|
|
b2b7bff4db | ||
|
|
217f8c5912 | ||
|
|
48aa7b264e | ||
|
|
a919bfcd28 | ||
|
|
f9697b7634 | ||
|
|
e21f0bddef | ||
|
|
96fc62864e | ||
|
|
cac4da695e | ||
|
|
22efda70bb | ||
|
|
fc15259c5e | ||
|
|
1a908b736a | ||
|
|
bc32f1b0fa | ||
|
|
ef4864d8d9 | ||
|
|
b90f32046f | ||
|
|
4672455e80 | ||
|
|
b650d6da4e | ||
|
|
f15dd88d04 | ||
|
|
cd4ae3e155 | ||
|
|
2946f624a5 | ||
|
|
57d1436760 | ||
|
|
157bfbda78 | ||
|
|
14553a2e5d | ||
|
|
1ed328a0d7 | ||
|
|
c4e2b684d2 | ||
|
|
c14a1acf9e | ||
|
|
fde36f597e | ||
|
|
b0821b18eb | ||
|
|
1bc6e00bb1 | ||
|
|
2bf01a60be | ||
|
|
9ca7351cec | ||
|
|
83d6fe4156 | ||
|
|
bf5d5af234 | ||
|
|
292241519f | ||
|
|
672629b214 | ||
|
|
3547f62336 | ||
|
|
6d005df6f7 | ||
|
|
c99948a2d1 | ||
|
|
c0c7e24862 | ||
|
|
07a6b195e7 | ||
|
|
3ab4e71ce7 | ||
|
|
8e6dff048a | ||
|
|
67a282e0cd | ||
|
|
1bfcdd264a | ||
|
|
15bb108d5f | ||
|
|
0bc9d2d64a | ||
|
|
77ba92a2ad | ||
|
|
4fe6697310 | ||
|
|
dfb02fb2cd | ||
|
|
b0978b5733 | ||
|
|
75b525e0e2 | ||
|
|
3992cba4f0 | ||
|
|
2b5c3808f5 | ||
|
|
dea2caf4b9 | ||
|
|
7be94525b8 | ||
|
|
82e0348c77 | ||
|
|
7070817c36 | ||
|
|
a76ff42a3b | ||
|
|
f6b2f35191 | ||
|
|
4420eee99f | ||
|
|
09759b282b | ||
|
|
37300101db | ||
|
|
e6aea36c3a | ||
|
|
34fa6fe307 | ||
|
|
fe5adb77df | ||
|
|
7ce3491760 | ||
|
|
a46544a8b0 | ||
|
|
4fd863634a | ||
|
|
79e67b2967 | ||
|
|
eae0c9e2df | ||
|
|
b4cb082f12 | ||
|
|
da98ddb057 | ||
|
|
0f650f4735 | ||
|
|
e145a3eb02 | ||
|
|
1fd5d06c72 | ||
|
|
c740cc2aeb | ||
|
|
31deb5f2f6 | ||
|
|
dfe7067a3f | ||
|
|
c0565b7ae7 | ||
|
|
484841f816 | ||
|
|
38b5e31e0e | ||
|
|
7540b23a0e | ||
|
|
280997bcfa | ||
|
|
e01d69c659 | ||
|
|
0b1d2b08f2 | ||
|
|
42871887be | ||
|
|
53c9a3c746 | ||
|
|
c5db839aa4 | ||
|
|
0d0adb6206 | ||
|
|
aa722ab271 | ||
|
|
b82655fe20 | ||
|
|
194a398db0 | ||
|
|
9bebced571 | ||
|
|
ae665c4fa1 | ||
|
|
ba5a29b790 | ||
|
|
cd4b3c9004 | ||
|
|
6cb913e09b | ||
|
|
feb9b8fe52 | ||
|
|
5070c3f408 | ||
|
|
b6c446b77e | ||
|
|
ce45421cb6 | ||
|
|
a6f4c90a05 | ||
|
|
20e16af964 | ||
|
|
1378dd73eb | ||
|
|
a5f3470200 | ||
|
|
8639f8f74e | ||
|
|
5bf7864b8c | ||
|
|
8ceccce6cd | ||
|
|
221ec8fe8f | ||
|
|
a1683b9efd | ||
|
|
f910c3b290 | ||
|
|
c7585c861c | ||
|
|
4f50b16caa | ||
|
|
32685c2040 | ||
|
|
57bcc39da2 | ||
|
|
a23808f09d | ||
|
|
472c2834e9 | ||
|
|
4114569b07 | ||
|
|
5f2e08e40a | ||
|
|
7065b59990 | ||
|
|
afa9d3959d | ||
|
|
c41d8c62f2 | ||
|
|
4dd49c1907 | ||
|
|
9bdb89e8ba | ||
|
|
e2cef60f80 | ||
|
|
8d129948e9 | ||
|
|
96facbf773 | ||
|
|
237bc205b8 | ||
|
|
fbeacd6c2e | ||
|
|
6f5c108a54 | ||
|
|
a908ec6d17 | ||
|
|
e4f03dac7d | ||
|
|
a721de0d00 | ||
|
|
d660c7868a | ||
|
|
26a58bbd36 | ||
|
|
ddec61f2a0 | ||
|
|
26f4998c74 | ||
|
|
84a7c3b270 | ||
|
|
102117a7d0 | ||
|
|
a337c6e311 | ||
|
|
69fabe97be | ||
|
|
28f0a65a4b | ||
|
|
4c33ac7a72 | ||
|
|
4276a38532 | ||
|
|
e10986608c | ||
|
|
7595e9e14c | ||
|
|
20c436f729 | ||
|
|
5ef439ae08 | ||
|
|
02f4147f02 | ||
|
|
4a4fe8f63e | ||
|
|
8cc5355693 | ||
|
|
8776b1ba58 | ||
|
|
b4498caada | ||
|
|
db269dae16 | ||
|
|
e4a45bb8b2 | ||
|
|
667fdaaac8 | ||
|
|
d22bce7905 | ||
|
|
49070f3bd3 | ||
|
|
ffa44f7b87 | ||
|
|
73001d1c98 | ||
|
|
d811a6d681 | ||
|
|
3c9184534e | ||
|
|
ebcee41c32 | ||
|
|
6f992a1cd4 | ||
|
|
010097b08c | ||
|
|
f04d0a9ad7 | ||
|
|
66ce5b6787 | ||
|
|
2bd5224c01 | ||
|
|
7412c459f8 | ||
|
|
fc0eeeb5c7 | ||
|
|
012f4ed508 | ||
|
|
a9f96b0513 |
@@ -1,50 +0,0 @@
|
||||
# Azure DevOps Pipelines
|
||||
|
||||
These yml files are used to provide CI builds using the Azure DevOps Pipeline Service.
|
||||
Most of the CI leverages edk2-pytools to support cross platform building and execution.
|
||||
|
||||
## Core CI
|
||||
|
||||
Focused on building and testing all packages in Edk2 without an actual target platform.
|
||||
|
||||
See `.pytools/ReadMe.py` for more details
|
||||
|
||||
## Platform CI
|
||||
|
||||
Focused on building a single target platform and confirming functionality on that platform.
|
||||
|
||||
## Conventions
|
||||
|
||||
* Files extension should be *.yml. *.yaml is also supported but in Edk2 we use those for our package configuration.
|
||||
* Platform CI files should be in the `<PlatformPkg>/.azurepipelines` folder.
|
||||
* Core CI files are in the root folder.
|
||||
* Shared templates are in the `templates` folder.
|
||||
* Top level CI files should be named `<host os>-<tool_chain_tag>.yml`
|
||||
|
||||
## Links
|
||||
|
||||
* Basic Azure Landing Site - https://docs.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops
|
||||
* Pipeline jobs - https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml
|
||||
* Pipeline yml scheme - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema
|
||||
* Pipeline expression - https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
|
||||
* PyTools - https://github.com/tianocore/edk2-pytool-extensions and https://github.com/tianocore/edk2-pytool-library
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
### Templates and parameters
|
||||
|
||||
They are great but evil. If they are used as part of determining the steps of a build they must resolve before the build starts. They can not use variables set in a yml or determined as part of a matrix. If they are used in a step then they can be bound late.
|
||||
|
||||
### File matching patterns
|
||||
|
||||
On Linux this can hang if there are too many files in the search list.
|
||||
|
||||
### Templates and file splitting
|
||||
|
||||
Suggestion is to do one big yaml file that does what you want for one of your targets. Then do the second one and find the deltas. From that you can start to figure out the right split of files, steps, jobs.
|
||||
|
||||
### Conditional steps
|
||||
|
||||
If you want the step to show up in the log but not run, use a step conditional. This is great when a platform doesn't currently support a feature but you want the builders to know that the features exists and maybe someday it will.
|
||||
|
||||
If you want the step to not show up use a template step conditional wrapper. Beware this will be evaluated early (at build start). This can hide things not needed on a given OS for example.
|
||||
@@ -1,21 +0,0 @@
|
||||
## @file
|
||||
# Azure Pipeline build file for a build using ubuntu and GCC5
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
trigger:
|
||||
- master
|
||||
- stable/*
|
||||
pr:
|
||||
- master
|
||||
- stable/*
|
||||
|
||||
jobs:
|
||||
- template: templates/pr-gate-build-job.yml
|
||||
parameters:
|
||||
tool_chain_tag: 'GCC5'
|
||||
vm_image: 'ubuntu-latest'
|
||||
arch_list: "IA32,X64,ARM,AARCH64,RISCV64"
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
## @file
|
||||
# Azure Pipielines YML file that evalues the patch series in a PR using the
|
||||
# python script BaseTools/Scripts/PatchCheck.py.
|
||||
#
|
||||
# NOTE: This example monitors pull requests against the edk2-ci branch. Most
|
||||
# environments would replace 'edk2-ci' with 'master'.
|
||||
#
|
||||
# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
# https://github.com/tianocore
|
||||
#
|
||||
##
|
||||
|
||||
trigger: none
|
||||
|
||||
pr:
|
||||
- master
|
||||
- stable/*
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
|
||||
steps:
|
||||
- checkout: self
|
||||
clean: true
|
||||
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
versionSpec: '3.7.x'
|
||||
architecture: 'x64'
|
||||
|
||||
- script: |
|
||||
git fetch origin $(System.PullRequest.TargetBranch):$(System.PullRequest.TargetBranch)
|
||||
python BaseTools/Scripts/PatchCheck.py $(System.PullRequest.TargetBranch)..$(System.PullRequest.SourceCommitId)
|
||||
displayName: 'Use PatchCheck.py to verify patch series in pull request'
|
||||
@@ -1,20 +0,0 @@
|
||||
## @file
|
||||
# Azure Pipeline build file for a build using Windows and VS2019
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
trigger:
|
||||
- master
|
||||
- stable/*
|
||||
|
||||
pr:
|
||||
- master
|
||||
- stable/*
|
||||
|
||||
jobs:
|
||||
- template: templates/pr-gate-build-job.yml
|
||||
parameters:
|
||||
tool_chain_tag: 'VS2019'
|
||||
vm_image: 'windows-latest'
|
||||
arch_list: "IA32,X64"
|
||||
@@ -1,59 +0,0 @@
|
||||
# CI Templates
|
||||
|
||||
This folder contains azure pipeline yml templates for "Core" and "Platform" Continuous Integration and PR validation.
|
||||
|
||||
## Common CI templates
|
||||
|
||||
### basetools-build-steps.yml
|
||||
|
||||
This template compiles the Edk2 basetools from source. The steps in this template are
|
||||
conditional and will only run if variable `pkg_count` is greater than 0.
|
||||
|
||||
It also has two conditional steps only used when the toolchain contains GCC. These two steps
|
||||
use `apt` to update the system packages and add those necessary for Edk2 builds.
|
||||
|
||||
## Core CI templates
|
||||
|
||||
### pr-gate-build-job.yml
|
||||
|
||||
This templates contains the jobs and most importantly the matrix of which packages and
|
||||
targets to run for Core CI.
|
||||
|
||||
### pr-gate-steps.yml
|
||||
|
||||
This template is the main Core CI template. It controls all the steps run and is responsible for most functionality of the Core CI process. This template sets
|
||||
the `pkg_count` variable using the `stuart_pr_eval` tool when the
|
||||
build type is "pull request"
|
||||
|
||||
### spell-check-prereq-steps.yml
|
||||
|
||||
This template installs the node based tools used by the spell checker plugin. The steps
|
||||
in this template are conditional and will only run if variable `pkg_count` is greater than 0.
|
||||
|
||||
## Platform CI templates
|
||||
|
||||
### platform-build-run-steps.yml
|
||||
|
||||
This template makes heavy use of pytools to build and run a platform in the Edk2 repo
|
||||
|
||||
Also uses basetools-build-steps.yml to compile basetools
|
||||
|
||||
#### Special Notes
|
||||
|
||||
* For a build type of pull request it will conditionally build if the patches change files that impact the platform.
|
||||
* uses `stuart_pr_eval` to determine impact
|
||||
* For manual builds or CI builds it will always build the platform
|
||||
* It compiles basetools from source
|
||||
* Will use `stuart_build --FlashOnly` to attempt to run the built image if the `Run` parameter is set.
|
||||
* See the parameters block for expected configuration options
|
||||
* Parameter `extra_install_step` allows the caller to insert extra steps. This is useful if additional dependencies, tools, or other things need to be installed. Here is an example of installing qemu on Windows.
|
||||
|
||||
``` yaml
|
||||
steps:
|
||||
- template: ../../.azurepipelines/templates/build-run-steps.yml
|
||||
parameters:
|
||||
extra_install_step:
|
||||
- powershell: choco install qemu; Write-Host "##vso[task.prependpath]c:\Program Files\qemu"
|
||||
displayName: Install QEMU and Set QEMU on path # friendly name displayed in the UI
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
```
|
||||
@@ -1,37 +0,0 @@
|
||||
## @file
|
||||
# File templates/basetools-build-job.yml
|
||||
#
|
||||
# template file to build basetools
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
parameters:
|
||||
tool_chain_tag: ''
|
||||
|
||||
steps:
|
||||
- ${{ if contains(parameters.tool_chain_tag, 'GCC') }}:
|
||||
- bash: sudo apt-get update
|
||||
displayName: Update apt
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
- bash: sudo apt-get install gcc g++ make uuid-dev
|
||||
displayName: Install required tools
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
- task: CmdLine@1
|
||||
displayName: Build Base Tools from source
|
||||
inputs:
|
||||
filename: python
|
||||
arguments: BaseTools/Edk2ToolsBuild.py -t ${{ parameters.tool_chain_tag }}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
- task: CopyFiles@2
|
||||
displayName: "Copy base tools build log"
|
||||
inputs:
|
||||
targetFolder: '$(Build.ArtifactStagingDirectory)'
|
||||
SourceFolder: 'BaseTools/BaseToolsBuild'
|
||||
contents: |
|
||||
BASETOOLS_BUILD*.*
|
||||
flattenFolders: true
|
||||
condition: and(gt(variables.pkg_count, 0), succeededOrFailed())
|
||||
@@ -1,140 +0,0 @@
|
||||
|
||||
## @file
|
||||
# File steps.yml
|
||||
#
|
||||
# template file containing the steps to build
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
parameters:
|
||||
- name: tool_chain_tag
|
||||
type: string
|
||||
default: ''
|
||||
- name: build_pkg
|
||||
type: string
|
||||
default: ''
|
||||
- name: build_target
|
||||
type: string
|
||||
default: ''
|
||||
- name: build_arch
|
||||
type: string
|
||||
default: ''
|
||||
- name: build_file
|
||||
type: string
|
||||
default: ''
|
||||
- name: build_flags
|
||||
type: string
|
||||
default: ''
|
||||
- name: run_flags
|
||||
type: string
|
||||
default: ''
|
||||
|
||||
- name: extra_install_step
|
||||
type: stepList
|
||||
default: []
|
||||
|
||||
steps:
|
||||
- checkout: self
|
||||
clean: true
|
||||
fetchDepth: 1
|
||||
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
versionSpec: "3.8.x"
|
||||
architecture: "x64"
|
||||
|
||||
- script: pip install -r pip-requirements.txt --upgrade
|
||||
displayName: 'Install/Upgrade pip modules'
|
||||
|
||||
# Set default
|
||||
- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
|
||||
|
||||
# Fetch the target branch so that pr_eval can diff them.
|
||||
# Seems like azure pipelines/github changed checkout process in nov 2020.
|
||||
- script: git fetch origin $(System.PullRequest.targetBranch)
|
||||
displayName: fetch target branch
|
||||
condition: eq(variables['Build.Reason'], 'PullRequest')
|
||||
|
||||
# trim the package list if this is a PR
|
||||
- task: CmdLine@1
|
||||
displayName: Check if ${{ parameters.build_pkg }} need testing
|
||||
inputs:
|
||||
filename: stuart_pr_eval
|
||||
arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
|
||||
condition: eq(variables['Build.Reason'], 'PullRequest')
|
||||
|
||||
# Setup repo
|
||||
- task: CmdLine@1
|
||||
displayName: Setup
|
||||
inputs:
|
||||
filename: stuart_setup
|
||||
arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
# Stuart Update
|
||||
- task: CmdLine@1
|
||||
displayName: Update
|
||||
inputs:
|
||||
filename: stuart_update
|
||||
arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
# build basetools
|
||||
# do this after setup and update so that code base dependencies
|
||||
# are all resolved.
|
||||
- template: basetools-build-steps.yml
|
||||
parameters:
|
||||
tool_chain_tag: ${{ parameters.tool_chain_tag }}
|
||||
|
||||
# Potential Extra steps
|
||||
- ${{ parameters.extra_install_step }}
|
||||
|
||||
# Build
|
||||
- task: CmdLine@1
|
||||
displayName: Build
|
||||
inputs:
|
||||
filename: stuart_build
|
||||
arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
# Run
|
||||
- task: CmdLine@1
|
||||
displayName: Run to shell
|
||||
inputs:
|
||||
filename: stuart_build
|
||||
arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
|
||||
condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
|
||||
timeoutInMinutes: 1
|
||||
|
||||
# Copy the build logs to the artifact staging directory
|
||||
- task: CopyFiles@2
|
||||
displayName: "Copy build logs"
|
||||
inputs:
|
||||
targetFolder: "$(Build.ArtifactStagingDirectory)"
|
||||
SourceFolder: "Build"
|
||||
contents: |
|
||||
BUILDLOG_*.txt
|
||||
BUILDLOG_*.md
|
||||
CI_*.txt
|
||||
CI_*.md
|
||||
CISETUP.txt
|
||||
SETUPLOG.txt
|
||||
UPDATE_LOG.txt
|
||||
PREVALLOG.txt
|
||||
TestSuites.xml
|
||||
**/BUILD_TOOLS_REPORT.html
|
||||
**/OVERRIDELOG.TXT
|
||||
BASETOOLS_BUILD*.*
|
||||
flattenFolders: true
|
||||
condition: succeededOrFailed()
|
||||
|
||||
# Publish build artifacts to Azure Artifacts/TFS or a file share
|
||||
- task: PublishBuildArtifacts@1
|
||||
continueOnError: true
|
||||
displayName: "Publish build logs"
|
||||
inputs:
|
||||
pathtoPublish: "$(Build.ArtifactStagingDirectory)"
|
||||
artifactName: "Build Logs $(System.JobName)"
|
||||
condition: succeededOrFailed()
|
||||
@@ -1,69 +0,0 @@
|
||||
## @file
|
||||
# File templates/pr-gate-build-job.yml
|
||||
#
|
||||
# template file used to build supported packages.
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
parameters:
|
||||
tool_chain_tag: ''
|
||||
vm_image: ''
|
||||
arch_list: ''
|
||||
|
||||
# Build step
|
||||
jobs:
|
||||
|
||||
- job: Build_${{ parameters.tool_chain_tag }}
|
||||
|
||||
#Use matrix to speed up the build process
|
||||
strategy:
|
||||
matrix:
|
||||
TARGET_ARM_ARMPLATFORM:
|
||||
Build.Pkgs: 'ArmPkg,ArmPlatformPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
|
||||
TARGET_MDE_CPU:
|
||||
Build.Pkgs: 'MdePkg,UefiCpuPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
|
||||
TARGET_MDEMODULE_DEBUG:
|
||||
Build.Pkgs: 'MdeModulePkg'
|
||||
Build.Targets: 'DEBUG,NOOPT'
|
||||
TARGET_MDEMODULE_RELEASE:
|
||||
Build.Pkgs: 'MdeModulePkg'
|
||||
Build.Targets: 'RELEASE,NO-TARGET'
|
||||
TARGET_NETWORK:
|
||||
Build.Pkgs: 'NetworkPkg,RedfishPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
|
||||
TARGET_OTHER:
|
||||
Build.Pkgs: 'PcAtChipsetPkg,ShellPkg,StandaloneMmPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
|
||||
TARGET_FMP_FAT_TEST:
|
||||
Build.Pkgs: 'FmpDevicePkg,FatPkg,UnitTestFrameworkPkg,DynamicTablesPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
|
||||
TARGET_CRYPTO:
|
||||
Build.Pkgs: 'CryptoPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
|
||||
TARGET_SECURITY:
|
||||
Build.Pkgs: 'SecurityPkg'
|
||||
Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
|
||||
TARGET_PLATFORMS:
|
||||
# For Platforms only check code. Leave it to Platform CI
|
||||
# to build them.
|
||||
Build.Pkgs: 'ArmVirtPkg,EmulatorPkg,OvmfPkg'
|
||||
Build.Targets: 'NO-TARGET'
|
||||
|
||||
workspace:
|
||||
clean: all
|
||||
|
||||
pool:
|
||||
vmImage: ${{ parameters.vm_image }}
|
||||
|
||||
steps:
|
||||
- template: pr-gate-steps.yml
|
||||
parameters:
|
||||
tool_chain_tag: ${{ parameters.tool_chain_tag }}
|
||||
build_pkgs: $(Build.Pkgs)
|
||||
build_targets: $(Build.Targets)
|
||||
build_archs: ${{ parameters.arch_list }}
|
||||
@@ -1,138 +0,0 @@
|
||||
## @file
|
||||
# File templates/pr-gate-steps.yml
|
||||
#
|
||||
# template file containing the steps to build
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
parameters:
|
||||
tool_chain_tag: ''
|
||||
build_pkgs: ''
|
||||
build_targets: ''
|
||||
build_archs: ''
|
||||
|
||||
steps:
|
||||
- checkout: self
|
||||
clean: true
|
||||
fetchDepth: 1
|
||||
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
versionSpec: '3.8.x'
|
||||
architecture: 'x64'
|
||||
|
||||
- script: pip install -r pip-requirements.txt --upgrade
|
||||
displayName: 'Install/Upgrade pip modules'
|
||||
|
||||
# Set default
|
||||
- bash: |
|
||||
echo "##vso[task.setvariable variable=pkgs_to_build]${{ parameters.build_pkgs }}"
|
||||
echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
|
||||
|
||||
# Fetch the target branch so that pr_eval can diff them.
|
||||
# Seems like azure pipelines/github changed checkout process in nov 2020.
|
||||
- script: git fetch origin $(System.PullRequest.targetBranch)
|
||||
displayName: fetch target branch
|
||||
condition: eq(variables['Build.Reason'], 'PullRequest')
|
||||
|
||||
# trim the package list if this is a PR
|
||||
- task: CmdLine@1
|
||||
displayName: Check if ${{ parameters.build_pkgs }} need testing
|
||||
inputs:
|
||||
filename: stuart_pr_eval
|
||||
arguments: -c .pytool/CISettings.py -p ${{ parameters.build_pkgs }} --pr-target origin/$(System.PullRequest.targetBranch) --output-csv-format-string "##vso[task.setvariable variable=pkgs_to_build;isOutpout=true]{pkgcsv}" --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
|
||||
condition: eq(variables['Build.Reason'], 'PullRequest')
|
||||
|
||||
# install spell check prereqs
|
||||
- template: spell-check-prereq-steps.yml
|
||||
|
||||
# Build repo
|
||||
- task: CmdLine@1
|
||||
displayName: Setup ${{ parameters.build_pkgs }} ${{ parameters.build_archs}}
|
||||
inputs:
|
||||
filename: stuart_setup
|
||||
arguments: -c .pytool/CISettings.py -p $(pkgs_to_build) -t ${{ parameters.build_targets}} -a ${{ parameters.build_archs}} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
- task: CmdLine@1
|
||||
displayName: Update ${{ parameters.build_pkgs }} ${{ parameters.build_archs}}
|
||||
inputs:
|
||||
filename: stuart_update
|
||||
arguments: -c .pytool/CISettings.py -p $(pkgs_to_build) -t ${{ parameters.build_targets}} -a ${{ parameters.build_archs}} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
# build basetools
|
||||
# do this after setup and update so that code base dependencies
|
||||
# are all resolved.
|
||||
- template: basetools-build-steps.yml
|
||||
parameters:
|
||||
tool_chain_tag: ${{ parameters.tool_chain_tag }}
|
||||
|
||||
- task: CmdLine@1
|
||||
displayName: Build and Test ${{ parameters.build_pkgs }} ${{ parameters.build_archs}}
|
||||
inputs:
|
||||
filename: stuart_ci_build
|
||||
arguments: -c .pytool/CISettings.py -p $(pkgs_to_build) -t ${{ parameters.build_targets}} -a ${{ parameters.build_archs}} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}}
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
# Publish Test Results to Azure Pipelines/TFS
|
||||
- task: PublishTestResults@2
|
||||
displayName: 'Publish junit test results'
|
||||
continueOnError: true
|
||||
condition: and( succeededOrFailed(),gt(variables.pkg_count, 0))
|
||||
inputs:
|
||||
testResultsFormat: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit
|
||||
testResultsFiles: 'Build/TestSuites.xml'
|
||||
#searchFolder: '$(System.DefaultWorkingDirectory)' # Optional
|
||||
mergeTestResults: true # Optional
|
||||
testRunTitle: $(System.JobName) # Optional
|
||||
#buildPlatform: # Optional
|
||||
#buildConfiguration: # Optional
|
||||
publishRunAttachments: true # Optional
|
||||
|
||||
# Publish Test Results to Azure Pipelines/TFS
|
||||
- task: PublishTestResults@2
|
||||
displayName: 'Publish host based test results for $(System.JobName)'
|
||||
continueOnError: true
|
||||
condition: and( succeededOrFailed(), gt(variables.pkg_count, 0))
|
||||
inputs:
|
||||
testResultsFormat: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit
|
||||
testResultsFiles: 'Build/**/*.result.xml'
|
||||
#searchFolder: '$(System.DefaultWorkingDirectory)' # Optional
|
||||
mergeTestResults: false # Optional
|
||||
testRunTitle: ${{ parameters.build_pkgs }} # Optional
|
||||
#buildPlatform: # Optional
|
||||
#buildConfiguration: # Optional
|
||||
publishRunAttachments: true # Optional
|
||||
|
||||
# Copy the build logs to the artifact staging directory
|
||||
- task: CopyFiles@2
|
||||
displayName: "Copy build logs"
|
||||
inputs:
|
||||
targetFolder: '$(Build.ArtifactStagingDirectory)'
|
||||
SourceFolder: 'Build'
|
||||
contents: |
|
||||
BUILDLOG_*.txt
|
||||
BUILDLOG_*.md
|
||||
CI_*.txt
|
||||
CI_*.md
|
||||
CISETUP.txt
|
||||
SETUPLOG.txt
|
||||
UPDATE_LOG.txt
|
||||
PREVALLOG.txt
|
||||
TestSuites.xml
|
||||
**/BUILD_TOOLS_REPORT.html
|
||||
**/OVERRIDELOG.TXT
|
||||
flattenFolders: true
|
||||
condition: succeededOrFailed()
|
||||
|
||||
# Publish build artifacts to Azure Artifacts/TFS or a file share
|
||||
- task: PublishBuildArtifacts@1
|
||||
continueOnError: true
|
||||
displayName: "Publish build logs"
|
||||
inputs:
|
||||
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
|
||||
artifactName: 'Build Logs $(System.JobName)'
|
||||
condition: succeededOrFailed()
|
||||
@@ -1,22 +0,0 @@
|
||||
## @file
|
||||
# File templates/spell-check-prereq-steps.yml
|
||||
#
|
||||
# template file used to install spell checking prerequisits
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
parameters:
|
||||
none: ''
|
||||
|
||||
steps:
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: '14.x'
|
||||
#checkLatest: false # Optional
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
|
||||
- script: npm install -g cspell
|
||||
displayName: 'Install cspell npm'
|
||||
condition: and(gt(variables.pkg_count, 0), succeeded())
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,7 +1,3 @@
|
||||
Build/
|
||||
.DS_Store
|
||||
*_extdep/
|
||||
*.pyc
|
||||
__pycache__/
|
||||
tags/
|
||||
.vscode/
|
||||
.DS_Store
|
||||
|
||||
19
.gitmodules
vendored
19
.gitmodules
vendored
@@ -1,22 +1,3 @@
|
||||
[submodule "CryptoPkg/Library/OpensslLib/openssl"]
|
||||
path = CryptoPkg/Library/OpensslLib/openssl
|
||||
url = https://github.com/openssl/openssl
|
||||
[submodule "SoftFloat"]
|
||||
path = ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3
|
||||
url = https://github.com/ucb-bar/berkeley-softfloat-3.git
|
||||
[submodule "UnitTestFrameworkPkg/Library/CmockaLib/cmocka"]
|
||||
path = UnitTestFrameworkPkg/Library/CmockaLib/cmocka
|
||||
url = https://github.com/tianocore/edk2-cmocka.git
|
||||
[submodule "MdeModulePkg/Universal/RegularExpressionDxe/oniguruma"]
|
||||
path = MdeModulePkg/Universal/RegularExpressionDxe/oniguruma
|
||||
url = https://github.com/kkos/oniguruma
|
||||
[submodule "MdeModulePkg/Library/BrotliCustomDecompressLib/brotli"]
|
||||
path = MdeModulePkg/Library/BrotliCustomDecompressLib/brotli
|
||||
url = https://github.com/google/brotli
|
||||
[submodule "BaseTools/Source/C/BrotliCompress/brotli"]
|
||||
path = BaseTools/Source/C/BrotliCompress/brotli
|
||||
url = https://github.com/google/brotli
|
||||
ignore = untracked
|
||||
[submodule "RedfishPkg/Library/JsonLib/jansson"]
|
||||
path = RedfishPkg/Library/JsonLib/jansson
|
||||
url = https://github.com/akheron/jansson
|
||||
|
||||
81
.mailmap
81
.mailmap
@@ -1,81 +0,0 @@
|
||||
#
|
||||
# This list is used by git-shortlog to update a few name translations
|
||||
# in the git archive to adjust for job changes or incorrect/inconsistent
|
||||
# name usage.
|
||||
#
|
||||
# Please keep this file sorted alphabetically, and email in lowercase.
|
||||
# The format used is:
|
||||
#
|
||||
# Firstname Lastname <email@domain.tld>
|
||||
#
|
||||
|
||||
Aaron Li <aaron.li@intel.com> <songpeng.li@intel.com>
|
||||
Antoine Cœur <coeur@gmx.fr>
|
||||
Antoine Cœur <coeur@gmx.fr> <Coeur@gmx.fr>
|
||||
Ard Biesheuvel <ard.biesheuvel@linaro.org> <abiesheuvel@Edk2>
|
||||
Ashley DeSimone <ashley.e.desimone@intel.com> <ashdesimone@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Baraneedharan Anbazhagan <anbazhagan@hp.com>
|
||||
Chasel Chiu <chasel.chiu@intel.com>
|
||||
Christopher J Zurcher <christopher.j.zurcher@intel.com>
|
||||
Eric Dong <eric.dong@intel.com>
|
||||
Eric Dong <eric.dong@intel.com> Eric Dong <eirc.dong@intel.com>
|
||||
Eric Dong <eric.dong@intel.com> <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Eric Dong <eric.dong@intel.com> <ydong10@Edk2>
|
||||
Erik Bjorge <erik.c.bjorge@intel.com> <geekboy15a@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Eugene Cohen <eugene@nuviainc.com>
|
||||
Eugene Cohen <eugene@nuviainc.com> <eugene@hp.com>
|
||||
Hao A Wu <hao.a.wu@intel.com>
|
||||
Hao A Wu <hao.a.wu@intel.com> <hwu1225@Edk2>
|
||||
Hot Tian <hot.tian@intel.com>
|
||||
Hot Tian <hot.tian@intel.com> <hhtian@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Jiewen Yao <jiewen.yao@intel.com>
|
||||
Jiewen Yao <jiewen.yao@intel.com> <Jiewen.yao@intel.com>
|
||||
Jiewen Yao <jiewen.yao@intel.com> <Jiewen.Yao@intel.com>
|
||||
Jiewen Yao <jiewen.yao@intel.com> <jyao1>
|
||||
Jiewen Yao <jiewen.yao@intel.com> <jyao1@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Jiewen Yao <jiewen.yao@intel.com> <jyao1@Edk2>
|
||||
Jim Dailey <Jim.Dailey@Dell.com>
|
||||
Jim Dailey <Jim.Dailey@Dell.com> <Jim_Dailey@Dell.com>
|
||||
Laszlo Ersek <lersek@redhat.com> <lersek@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Laszlo Ersek <lersek@redhat.com> <lersek@Edk2>
|
||||
Liming Gao <gaoliming@byosoft.com.cn>
|
||||
Liming Gao <liming.gao@intel.com> <Gao, Liming liming.gao@intel.com>
|
||||
Liming Gao <liming.gao@intel.com> <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Liming Gao <liming.gao@intel.com> <lgao4@Edk2>
|
||||
Liming Gao <liming.gao@intel.com> <liming.gao@intel.com>
|
||||
Maciej Rabeda <maciej.rabeda@intel.com>
|
||||
Marc-André Lureau <marcandre.lureau@redhat.com> <marcandre.lureau@redhat.com>
|
||||
Marvin Häuser <Marvin.Haeuser@outlook.com>
|
||||
Marvin Häuser <Marvin.Haeuser@outlook.com> edk2-devel <edk2-devel-bounces@lists.01.org>
|
||||
Marvin Häuser <mhaeuser@outlook.de>
|
||||
Matt DeVillier <matt.devillier@gmail.com>
|
||||
Maurice Ma <maurice.ma@intel.com>
|
||||
Michael Kubacki <michael.a.kubacki@intel.com>
|
||||
Michael Kubacki <michael.a.kubacki@intel.com> </o=Intel/ou=External (FYDIBOHF25SPDLT)/cn=Recipients/cn=3c8b0226e75f4ab08d20c151cb7a8a72>
|
||||
Ming Tan <ming.tan@intel.com>
|
||||
Nikolai Saoukh <nms@otdel-1.org>
|
||||
Philippe Mathieu-Daudé <philmd@redhat.com>
|
||||
Ray Ni <ray.ni@intel.com>
|
||||
Ray Ni <ray.ni@intel.com> <C:/Program Files (x86)/Git/O=Intel/OU=Pacifica02/cn=Recipients/cn=rni2>
|
||||
Ray Ni <ray.ni@intel.com> <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Ray Ni <ray.ni@intel.com> <niruiyu@Edk2>
|
||||
Ray Ni <ray.ni@intel.com> <ruiyu.ni@intel.com>
|
||||
Ray Ni <ray.ni@intel.com> <Ruiyu.ni@Intel.com>
|
||||
Ray Ni <ray.ni@intel.com> <ruyu.ni@intel.com>
|
||||
Rebecca Cran <rebecca@bluestop.org>
|
||||
Rebecca Cran <rebecca@bsdio.com>
|
||||
Samer El-Haj-Mahmoud <samer@elhajmahmoud.com> <elhaj@hpe.com>
|
||||
Samer El-Haj-Mahmoud <samer@elhajmahmoud.com> <Samer El-Haj-Mahmoud elhaj@hp.com>
|
||||
Shenglei Zhang <shenglei.zhang@intel.com>
|
||||
Star Zeng <star.zeng@intel.com>
|
||||
Star Zeng <star.zeng@intel.com> <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
|
||||
Star Zeng <star.zeng@intel.com> <lzeng14@Edk2>
|
||||
Tom Lendacky <thomas.lendacky@amd.com>
|
||||
Vitaly Cheptsov <vit9696@protonmail.com> Vitaly Cheptsov via Groups.Io <vit9696=protonmail.com@groups.io>
|
||||
Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com> Vladimir Olovyannikov via edk2-devel <edk2-devel@lists.01.org>
|
||||
Wei6 Xu <wei6.xu@intel.com>
|
||||
Yonghong Zhu <yonghong.zhu@intel.com>
|
||||
Yonghong Zhu <yonghong.zhu@intel.com> <yzhu52@Edk2>
|
||||
Yu-Chen Lin <yuchenlin@synology.com>
|
||||
Zhichao Gao <zhichao.gao@intel.com>
|
||||
Zhiguang Liu <zhiguang.liu@intel.com>
|
||||
@@ -1,50 +0,0 @@
|
||||
## @file
|
||||
# Mergify YML file that automatically merges a GitHub pull request against
|
||||
# edk2-ci if all of the GitHub branch protections have passed. It also
|
||||
# contains rules to:
|
||||
# * auto close branches that are not from an EDK II Maintainer
|
||||
# * post a comment on pull requests that have merge conflicts.
|
||||
# * post a comment on pull requests that have PatchCheck.py errors.
|
||||
#
|
||||
# Configuration Notes:
|
||||
# * Update the 'base=edk2-ci' statements with the name of the branch to merge
|
||||
# pull requests.
|
||||
#
|
||||
# * Update the 'status-failure' statement with the name of the name of the Azure
|
||||
# Pipelines Build that performs the EDK II Maintainer check.
|
||||
#
|
||||
# * This file must be checked into the 'default' branch of a repo. Copies
|
||||
# of this file on other branches of a repo are ignored by Mergify.
|
||||
#
|
||||
# Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
# https://github.com/apps/mergify
|
||||
# https://doc.mergify.io/
|
||||
#
|
||||
##
|
||||
|
||||
queue_rules:
|
||||
- name: default
|
||||
conditions:
|
||||
- base~=(^main|^master|^stable/)
|
||||
- label=push
|
||||
|
||||
pull_request_rules:
|
||||
- name: Automatically merge a PR when all required checks pass and 'push' label is present
|
||||
conditions:
|
||||
- base~=(^main|^master|^stable/)
|
||||
- label=push
|
||||
actions:
|
||||
queue:
|
||||
method: rebase
|
||||
rebase_fallback: none
|
||||
name: default
|
||||
|
||||
- name: Post a comment on a PR that can not be merged due to a merge conflict
|
||||
conditions:
|
||||
- base~=(^main|^master|^stable/)
|
||||
- conflict
|
||||
actions:
|
||||
comment:
|
||||
message: PR can not be merged due to conflict. Please rebase and resubmit
|
||||
@@ -1,227 +0,0 @@
|
||||
# @file
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
|
||||
# Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
import os
|
||||
import logging
|
||||
from edk2toolext.environment import shell_environment
|
||||
from edk2toolext.invocables.edk2_ci_build import CiBuildSettingsManager
|
||||
from edk2toolext.invocables.edk2_setup import SetupSettingsManager, RequiredSubmodule
|
||||
from edk2toolext.invocables.edk2_update import UpdateSettingsManager
|
||||
from edk2toolext.invocables.edk2_pr_eval import PrEvalSettingsManager
|
||||
from edk2toollib.utility_functions import GetHostInfo
|
||||
|
||||
|
||||
class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManager, PrEvalSettingsManager):
|
||||
|
||||
def __init__(self):
|
||||
self.ActualPackages = []
|
||||
self.ActualTargets = []
|
||||
self.ActualArchitectures = []
|
||||
self.ActualToolChainTag = ""
|
||||
self.UseBuiltInBaseTools = None
|
||||
self.ActualScopes = None
|
||||
|
||||
# ####################################################################################### #
|
||||
# Extra CmdLine configuration #
|
||||
# ####################################################################################### #
|
||||
|
||||
def AddCommandLineOptions(self, parserObj):
|
||||
group = parserObj.add_mutually_exclusive_group()
|
||||
group.add_argument("-force_piptools", "--fpt", dest="force_piptools", action="store_true", default=False, help="Force the system to use pip tools")
|
||||
group.add_argument("-no_piptools", "--npt", dest="no_piptools", action="store_true", default=False, help="Force the system to not use pip tools")
|
||||
|
||||
def RetrieveCommandLineOptions(self, args):
|
||||
super().RetrieveCommandLineOptions(args)
|
||||
if args.force_piptools:
|
||||
self.UseBuiltInBaseTools = True
|
||||
if args.no_piptools:
|
||||
self.UseBuiltInBaseTools = False
|
||||
|
||||
# ####################################################################################### #
|
||||
# Default Support for this Ci Build #
|
||||
# ####################################################################################### #
|
||||
|
||||
def GetPackagesSupported(self):
|
||||
''' return iterable of edk2 packages supported by this build.
|
||||
These should be edk2 workspace relative paths '''
|
||||
|
||||
return ("ArmPkg",
|
||||
"ArmPlatformPkg",
|
||||
"ArmVirtPkg",
|
||||
"DynamicTablesPkg",
|
||||
"EmulatorPkg",
|
||||
"MdePkg",
|
||||
"MdeModulePkg",
|
||||
"NetworkPkg",
|
||||
"PcAtChipsetPkg",
|
||||
"SecurityPkg",
|
||||
"UefiCpuPkg",
|
||||
"FmpDevicePkg",
|
||||
"ShellPkg",
|
||||
"StandaloneMmPkg",
|
||||
"FatPkg",
|
||||
"CryptoPkg",
|
||||
"UnitTestFrameworkPkg",
|
||||
"OvmfPkg",
|
||||
"RedfishPkg"
|
||||
)
|
||||
|
||||
def GetArchitecturesSupported(self):
|
||||
''' return iterable of edk2 architectures supported by this build '''
|
||||
return (
|
||||
"IA32",
|
||||
"X64",
|
||||
"ARM",
|
||||
"AARCH64",
|
||||
"RISCV64")
|
||||
|
||||
def GetTargetsSupported(self):
|
||||
''' return iterable of edk2 target tags supported by this build '''
|
||||
return ("DEBUG", "RELEASE", "NO-TARGET", "NOOPT")
|
||||
|
||||
# ####################################################################################### #
|
||||
# Verify and Save requested Ci Build Config #
|
||||
# ####################################################################################### #
|
||||
|
||||
def SetPackages(self, list_of_requested_packages):
|
||||
''' Confirm the requested package list is valid and configure SettingsManager
|
||||
to build the requested packages.
|
||||
|
||||
Raise UnsupportedException if a requested_package is not supported
|
||||
'''
|
||||
unsupported = set(list_of_requested_packages) - \
|
||||
set(self.GetPackagesSupported())
|
||||
if(len(unsupported) > 0):
|
||||
logging.critical(
|
||||
"Unsupported Package Requested: " + " ".join(unsupported))
|
||||
raise Exception("Unsupported Package Requested: " +
|
||||
" ".join(unsupported))
|
||||
self.ActualPackages = list_of_requested_packages
|
||||
|
||||
def SetArchitectures(self, list_of_requested_architectures):
|
||||
''' Confirm the requests architecture list is valid and configure SettingsManager
|
||||
to run only the requested architectures.
|
||||
|
||||
Raise Exception if a list_of_requested_architectures is not supported
|
||||
'''
|
||||
unsupported = set(list_of_requested_architectures) - \
|
||||
set(self.GetArchitecturesSupported())
|
||||
if(len(unsupported) > 0):
|
||||
logging.critical(
|
||||
"Unsupported Architecture Requested: " + " ".join(unsupported))
|
||||
raise Exception(
|
||||
"Unsupported Architecture Requested: " + " ".join(unsupported))
|
||||
self.ActualArchitectures = list_of_requested_architectures
|
||||
|
||||
def SetTargets(self, list_of_requested_target):
|
||||
''' Confirm the request target list is valid and configure SettingsManager
|
||||
to run only the requested targets.
|
||||
|
||||
Raise UnsupportedException if a requested_target is not supported
|
||||
'''
|
||||
unsupported = set(list_of_requested_target) - \
|
||||
set(self.GetTargetsSupported())
|
||||
if(len(unsupported) > 0):
|
||||
logging.critical(
|
||||
"Unsupported Targets Requested: " + " ".join(unsupported))
|
||||
raise Exception("Unsupported Targets Requested: " +
|
||||
" ".join(unsupported))
|
||||
self.ActualTargets = list_of_requested_target
|
||||
|
||||
# ####################################################################################### #
|
||||
# Actual Configuration for Ci Build #
|
||||
# ####################################################################################### #
|
||||
|
||||
def GetActiveScopes(self):
|
||||
''' return tuple containing scopes that should be active for this process '''
|
||||
if self.ActualScopes is None:
|
||||
scopes = ("cibuild", "edk2-build", "host-based-test")
|
||||
|
||||
self.ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")
|
||||
|
||||
is_linux = GetHostInfo().os.upper() == "LINUX"
|
||||
|
||||
if self.UseBuiltInBaseTools is None:
|
||||
is_linux = GetHostInfo().os.upper() == "LINUX"
|
||||
# try and import the pip module for basetools
|
||||
try:
|
||||
import edk2basetools
|
||||
self.UseBuiltInBaseTools = True
|
||||
except ImportError:
|
||||
self.UseBuiltInBaseTools = False
|
||||
pass
|
||||
|
||||
if self.UseBuiltInBaseTools == True:
|
||||
scopes += ('pipbuild-unix',) if is_linux else ('pipbuild-win',)
|
||||
logging.warning("Using Pip Tools based BaseTools")
|
||||
else:
|
||||
logging.warning("Falling back to using in-tree BaseTools")
|
||||
|
||||
if is_linux and self.ActualToolChainTag.upper().startswith("GCC"):
|
||||
if "AARCH64" in self.ActualArchitectures:
|
||||
scopes += ("gcc_aarch64_linux",)
|
||||
if "ARM" in self.ActualArchitectures:
|
||||
scopes += ("gcc_arm_linux",)
|
||||
if "RISCV64" in self.ActualArchitectures:
|
||||
scopes += ("gcc_riscv64_unknown",)
|
||||
self.ActualScopes = scopes
|
||||
return self.ActualScopes
|
||||
|
||||
def GetRequiredSubmodules(self):
|
||||
''' return iterable containing RequiredSubmodule objects.
|
||||
If no RequiredSubmodules return an empty iterable
|
||||
'''
|
||||
rs = []
|
||||
rs.append(RequiredSubmodule(
|
||||
"ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"CryptoPkg/Library/OpensslLib/openssl", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"UnitTestFrameworkPkg/Library/CmockaLib/cmocka", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"MdeModulePkg/Universal/RegularExpressionDxe/oniguruma", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"MdeModulePkg/Library/BrotliCustomDecompressLib/brotli", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"BaseTools/Source/C/BrotliCompress/brotli", False))
|
||||
rs.append(RequiredSubmodule(
|
||||
"RedfishPkg/Library/JsonLib/jansson", False))
|
||||
return rs
|
||||
|
||||
def GetName(self):
|
||||
return "Edk2"
|
||||
|
||||
def GetDependencies(self):
|
||||
return [
|
||||
]
|
||||
|
||||
def GetPackagesPath(self):
|
||||
return ()
|
||||
|
||||
def GetWorkspaceRoot(self):
|
||||
''' get WorkspacePath '''
|
||||
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:
|
||||
''' Filter potential packages to test based on changed files. '''
|
||||
build_these_packages = []
|
||||
possible_packages = potentialPackagesList.copy()
|
||||
for f in changedFilesList:
|
||||
# split each part of path for comparison later
|
||||
nodes = f.split("/")
|
||||
|
||||
# python file change in .pytool folder causes building all
|
||||
if f.endswith(".py") and ".pytool" in nodes:
|
||||
build_these_packages = possible_packages
|
||||
break
|
||||
|
||||
# BaseTools files that might change the build
|
||||
if "BaseTools" in nodes:
|
||||
if os.path.splitext(f) not in [".txt", ".md"]:
|
||||
build_these_packages = possible_packages
|
||||
break
|
||||
return build_these_packages
|
||||
@@ -1,118 +0,0 @@
|
||||
# @file CharEncodingCheck.py
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
|
||||
import os
|
||||
import logging
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
##
|
||||
# map
|
||||
##
|
||||
EcodingMap = {
|
||||
".md": 'utf-8',
|
||||
".dsc": 'utf-8',
|
||||
".dec": 'utf-8',
|
||||
".c": 'utf-8',
|
||||
".h": 'utf-8',
|
||||
".asm": 'utf-8',
|
||||
".masm": 'utf-8',
|
||||
".nasm": 'utf-8',
|
||||
".s": 'utf-8',
|
||||
".inf": 'utf-8',
|
||||
".asl": 'utf-8',
|
||||
".uni": 'utf-8',
|
||||
".py": 'utf-8'
|
||||
}
|
||||
|
||||
|
||||
class CharEncodingCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that scans each file in the code tree and confirms the encoding is correct.
|
||||
|
||||
Configuration options:
|
||||
"CharEncodingCheck": {
|
||||
"IgnoreFiles": []
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
"""
|
||||
return ("Check for valid file encoding for " + packagename, packagename + ".CharEncodingCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the ci_build_plugin Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
overall_status = 0
|
||||
files_tested = 0
|
||||
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)
|
||||
|
||||
if abs_pkg_path is None:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No Package folder {0}".format(abs_pkg_path))
|
||||
return 0
|
||||
|
||||
for (ext, enc) in EcodingMap.items():
|
||||
files = self.WalkDirectoryForExtension([ext], abs_pkg_path)
|
||||
files = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(x) for x in files] # make edk2relative path so can process ignores
|
||||
|
||||
if "IgnoreFiles" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreFiles"]:
|
||||
a = a.replace(os.sep, "/")
|
||||
try:
|
||||
tc.LogStdOut("Ignoring File {0}".format(a))
|
||||
files.remove(a)
|
||||
except:
|
||||
tc.LogStdError("CharEncodingCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
logging.info("CharEncodingCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
|
||||
files = [Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(x) for x in files]
|
||||
for a in files:
|
||||
files_tested += 1
|
||||
if(self.TestEncodingOk(a, enc)):
|
||||
logging.debug("File {0} Passed Encoding Check {1}".format(a, enc))
|
||||
else:
|
||||
tc.LogStdError("Encoding Failure in {0}. Not {1}".format(a, enc))
|
||||
overall_status += 1
|
||||
|
||||
tc.LogStdOut("Tested Encoding on {0} files".format(files_tested))
|
||||
if overall_status != 0:
|
||||
tc.SetFailed("CharEncoding {0} Failed. Errors {1}".format(packagename, overall_status), "CHAR_ENCODING_CHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
|
||||
def TestEncodingOk(self, apath, encodingValue):
|
||||
try:
|
||||
with open(apath, "rb") as fobj:
|
||||
fobj.read().decode(encodingValue)
|
||||
except Exception as exp:
|
||||
logging.error("Encoding failure: file: {0} type: {1}".format(apath, encodingValue))
|
||||
logging.debug("EXCEPTION: while processing {1} - {0}".format(exp, apath))
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check char encoding
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Char Encoding Check Test",
|
||||
"module": "CharEncodingCheck"
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
# Character Encoding Check Plugin
|
||||
|
||||
This CiBuildPlugin scans all the files in a package to make sure each file is
|
||||
correctly encoded and all characters can be read. Improper encoding causes
|
||||
tools to fail in some situations especially in different locals.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin can be configured to ignore certain files.
|
||||
|
||||
``` yaml
|
||||
"CharEncodingCheck": {
|
||||
"IgnoreFiles": []
|
||||
}
|
||||
```
|
||||
### IgnoreFiles
|
||||
|
||||
OPTIONAL List of file to ignore.
|
||||
@@ -1,102 +0,0 @@
|
||||
# @file CompilerPlugin.py
|
||||
##
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toolext.environment.uefi_build import UefiBuilder
|
||||
from edk2toolext import edk2_logging
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
|
||||
class CompilerPlugin(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that compiles the package dsc
|
||||
from the package being tested.
|
||||
|
||||
Configuration options:
|
||||
"CompilerPlugin": {
|
||||
"DscPath": "<path to dsc from root of pkg>"
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
"""
|
||||
target = environment.GetValue("TARGET")
|
||||
return ("Compile " + packagename + " " + target, packagename + ".Compiler." + target)
|
||||
|
||||
def RunsOnTargetList(self):
|
||||
return ["DEBUG", "RELEASE"]
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the ICiBuildPlugin Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
self._env = environment
|
||||
|
||||
# Parse the config for required DscPath element
|
||||
if "DscPath" not in pkgconfig:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("DscPath not found in config file. Nothing to compile.")
|
||||
return -1
|
||||
|
||||
AP = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)
|
||||
|
||||
APDSC = os.path.join(AP, pkgconfig["DscPath"].strip())
|
||||
AP_Path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(APDSC)
|
||||
if AP is None or AP_Path is None or not os.path.isfile(APDSC):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("Package Dsc not found.")
|
||||
return -1
|
||||
|
||||
logging.info("Building {0}".format(AP_Path))
|
||||
self._env.SetValue("ACTIVE_PLATFORM", AP_Path, "Set in Compiler Plugin")
|
||||
|
||||
# Parse DSC to check for SUPPORTED_ARCHITECTURES
|
||||
dp = DscParser()
|
||||
dp.SetBaseAbsPath(Edk2pathObj.WorkspacePath)
|
||||
dp.SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
dp.ParseFile(AP_Path)
|
||||
if "SUPPORTED_ARCHITECTURES" in dp.LocalVars:
|
||||
SUPPORTED_ARCHITECTURES = dp.LocalVars["SUPPORTED_ARCHITECTURES"].split('|')
|
||||
TARGET_ARCHITECTURES = environment.GetValue("TARGET_ARCH").split(' ')
|
||||
|
||||
# Skip if there is no intersection between SUPPORTED_ARCHITECTURES and TARGET_ARCHITECTURES
|
||||
if len(set(SUPPORTED_ARCHITECTURES) & set(TARGET_ARCHITECTURES)) == 0:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No supported architecutres to build")
|
||||
return -1
|
||||
|
||||
uefiBuilder = UefiBuilder()
|
||||
# do all the steps
|
||||
# WorkSpace, PackagesPath, PInHelper, PInManager
|
||||
ret = uefiBuilder.Go(Edk2pathObj.WorkspacePath, os.pathsep.join(Edk2pathObj.PackagePathList), PLMHelper, PLM)
|
||||
if ret != 0: # failure:
|
||||
tc.SetFailed("Compile failed for {0}".format(packagename), "Compile_FAILED")
|
||||
tc.LogStdError("{0} Compile failed with error code {1} ".format(AP_Path, ret))
|
||||
return 1
|
||||
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return 0
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to compile each package
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Compiler Plugin",
|
||||
"module": "CompilerPlugin"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
# Compiler Plugin
|
||||
|
||||
This CiBuildPlugin compiles the package DSC from the package being tested.
|
||||
|
||||
## Configuration
|
||||
|
||||
The package relative path of the DSC file to build.
|
||||
|
||||
``` yaml
|
||||
"CompilerPlugin": {
|
||||
"DscPath": "<path to dsc from root of pkg>"
|
||||
}
|
||||
```
|
||||
|
||||
### DscPath
|
||||
|
||||
Package relative path to the DSC file to build.
|
||||
@@ -1,120 +0,0 @@
|
||||
# @file dependency_check.py
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
import logging
|
||||
import os
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toollib.uefi.edk2.parsers.inf_parser import InfParser
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
|
||||
class DependencyCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that finds all modules (inf files) in a package and reviews the packages used
|
||||
to confirm they are acceptable. This is to help enforce layering and identify improper
|
||||
dependencies between packages.
|
||||
|
||||
Configuration options:
|
||||
"DependencyCheck": {
|
||||
"AcceptableDependencies": [], # Package dec files that are allowed in all INFs. Example: MdePkg/MdePkg.dec
|
||||
"AcceptableDependencies-<MODULE_TYPE>": [], # OPTIONAL Package dependencies for INFs that are HOST_APPLICATION
|
||||
"AcceptableDependencies-HOST_APPLICATION": [], # EXAMPLE Package dependencies for INFs that are HOST_APPLICATION
|
||||
"IgnoreInf": [] # Ignore INF if found in filesystem
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
"""
|
||||
return ("Test Package Dependencies for modules in " + packagename, packagename + ".DependencyCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the MuBuild Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
overall_status = 0
|
||||
|
||||
# Get current platform
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)
|
||||
|
||||
# Get INF Files
|
||||
INFFiles = self.WalkDirectoryForExtension([".inf"], abs_pkg_path)
|
||||
INFFiles = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(x) for x in INFFiles] # make edk2relative path so can compare with Ignore List
|
||||
|
||||
# Remove ignored INFs
|
||||
if "IgnoreInf" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreInf"]:
|
||||
a = a.replace(os.sep, "/") ## convert path sep in case ignore list is bad. Can't change case
|
||||
try:
|
||||
INFFiles.remove(a)
|
||||
tc.LogStdOut("IgnoreInf {0}".format(a))
|
||||
except:
|
||||
logging.info("DependencyConfig.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
tc.LogStdError("DependencyConfig.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
|
||||
|
||||
# Get the AccpetableDependencies list
|
||||
if "AcceptableDependencies" not in pkgconfig:
|
||||
logging.info("DependencyCheck Skipped. No Acceptable Dependencies defined.")
|
||||
tc.LogStdOut("DependencyCheck Skipped. No Acceptable Dependencies defined.")
|
||||
tc.SetSkipped()
|
||||
return -1
|
||||
|
||||
# Log dependencies
|
||||
for k in pkgconfig.keys():
|
||||
if k.startswith("AcceptableDependencies"):
|
||||
pkgstring = "\n".join(pkgconfig[k])
|
||||
if ("-" in k):
|
||||
_, _, mod_type = k.partition("-")
|
||||
tc.LogStdOut(f"Additional dependencies for MODULE_TYPE {mod_type}:\n {pkgstring}")
|
||||
else:
|
||||
tc.LogStdOut(f"Acceptable Dependencies:\n {pkgstring}")
|
||||
|
||||
# For each INF file
|
||||
for file in INFFiles:
|
||||
ip = InfParser()
|
||||
logging.debug("Parsing " + file)
|
||||
ip.SetBaseAbsPath(Edk2pathObj.WorkspacePath).SetPackagePaths(Edk2pathObj.PackagePathList).ParseFile(file)
|
||||
|
||||
if("MODULE_TYPE" not in ip.Dict):
|
||||
tc.LogStdOut("Ignoring INF. Missing key for MODULE_TYPE {0}".format(file))
|
||||
continue
|
||||
|
||||
mod_type = ip.Dict["MODULE_TYPE"].upper()
|
||||
for p in ip.PackagesUsed:
|
||||
if p not in pkgconfig["AcceptableDependencies"]:
|
||||
# If not in the main acceptable dependencies list then check module specific
|
||||
mod_specific_key = "AcceptableDependencies-" + mod_type
|
||||
if mod_specific_key in pkgconfig and p in pkgconfig[mod_specific_key]:
|
||||
continue
|
||||
|
||||
logging.error("Dependency Check: Invalid Dependency INF: {0} depends on pkg {1}".format(file, p))
|
||||
tc.LogStdError("Dependency Check: Invalid Dependency INF: {0} depends on pkg {1}".format(file, p))
|
||||
overall_status += 1
|
||||
|
||||
# If XML object exists, add results
|
||||
if overall_status != 0:
|
||||
tc.SetFailed("Failed with {0} errors".format(overall_status), "DEPENDENCYCHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
@@ -1,13 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check all infs within a package
|
||||
# to confirm the packagesdependency are on the configured list of acceptable
|
||||
# dependencies.
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Dependency Check Test",
|
||||
"module": "DependencyCheck"
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
# Depdendency Check Plugin
|
||||
|
||||
A CiBuildPlugin that finds all modules (inf files) in a package and reviews the
|
||||
packages used to confirm they are acceptable. This is to help enforce layering
|
||||
and identify improper dependencies between packages.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin must be configured with the acceptabe package dependencies for the
|
||||
package.
|
||||
|
||||
``` yaml
|
||||
"DependencyCheck": {
|
||||
"AcceptableDependencies": [],
|
||||
"AcceptableDependencies-<MODULE_TYPE>": [],
|
||||
"IgnoreInf": []
|
||||
}
|
||||
```
|
||||
|
||||
### AcceptableDependencies
|
||||
|
||||
Package dec files that are allowed in all INFs. Example: MdePkg/MdePkg.dec
|
||||
|
||||
### AcceptableDependencies-<MODULE_TYPE>
|
||||
|
||||
OPTIONAL Package dependencies for INFs that have module type <MODULE_TYPE>.
|
||||
Example: AcceptableDependencies-HOST_APPLICATION.
|
||||
|
||||
### IgnoreInf
|
||||
|
||||
OPTIONAL list of INFs to ignore for this dependency check.
|
||||
@@ -1,133 +0,0 @@
|
||||
# @file DscCompleteCheck.py
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
import logging
|
||||
import os
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser
|
||||
from edk2toollib.uefi.edk2.parsers.inf_parser import InfParser
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
|
||||
class DscCompleteCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that scans the package dsc file and confirms all modules (inf files) are
|
||||
listed in the components sections.
|
||||
|
||||
Configuration options:
|
||||
"DscCompleteCheck": {
|
||||
"DscPath": "<path to dsc from root of pkg>"
|
||||
"IgnoreInf": [] # Ignore INF if found in filesystem by not dsc
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
"""
|
||||
return ("Check the " + packagename + " DSC for a being complete", packagename + ".DscCompleteCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the MuBuild Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - VarDict containing the shell environment Build Vars
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
overall_status = 0
|
||||
|
||||
# Parse the config for required DscPath element
|
||||
if "DscPath" not in pkgconfig:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError(
|
||||
"DscPath not found in config file. Nothing to check.")
|
||||
return -1
|
||||
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(
|
||||
packagename)
|
||||
abs_dsc_path = os.path.join(abs_pkg_path, pkgconfig["DscPath"].strip())
|
||||
wsr_dsc_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(
|
||||
abs_dsc_path)
|
||||
|
||||
if abs_dsc_path is None or wsr_dsc_path == "" or not os.path.isfile(abs_dsc_path):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("Package Dsc not found")
|
||||
return 0
|
||||
|
||||
# Get INF Files
|
||||
INFFiles = self.WalkDirectoryForExtension([".inf"], abs_pkg_path)
|
||||
INFFiles = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(
|
||||
x) for x in INFFiles] # make edk2relative path so can compare with DSC
|
||||
|
||||
# remove ignores
|
||||
|
||||
if "IgnoreInf" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreInf"]:
|
||||
a = a.replace(os.sep, "/")
|
||||
try:
|
||||
tc.LogStdOut("Ignoring INF {0}".format(a))
|
||||
INFFiles.remove(a)
|
||||
except:
|
||||
tc.LogStdError(
|
||||
"DscCompleteCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
logging.info(
|
||||
"DscCompleteCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
|
||||
# DSC Parser
|
||||
dp = DscParser()
|
||||
dp.SetBaseAbsPath(Edk2pathObj.WorkspacePath)
|
||||
dp.SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
dp.SetInputVars(environment.GetAllBuildKeyValues())
|
||||
dp.ParseFile(wsr_dsc_path)
|
||||
|
||||
# Check if INF in component section
|
||||
for INF in INFFiles:
|
||||
if not any(INF.strip() in x for x in dp.ThreeMods) and \
|
||||
not any(INF.strip() in x for x in dp.SixMods) and \
|
||||
not any(INF.strip() in x for x in dp.OtherMods):
|
||||
|
||||
infp = InfParser().SetBaseAbsPath(Edk2pathObj.WorkspacePath)
|
||||
infp.SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
infp.ParseFile(INF)
|
||||
if("MODULE_TYPE" not in infp.Dict):
|
||||
tc.LogStdOut(
|
||||
"Ignoring INF. Missing key for MODULE_TYPE {0}".format(INF))
|
||||
continue
|
||||
|
||||
if(infp.Dict["MODULE_TYPE"] == "HOST_APPLICATION"):
|
||||
tc.LogStdOut(
|
||||
"Ignoring INF. Module type is HOST_APPLICATION {0}".format(INF))
|
||||
continue
|
||||
|
||||
if len(infp.SupportedPhases) == 1 and \
|
||||
"HOST_APPLICATION" in infp.SupportedPhases:
|
||||
tc.LogStdOut(
|
||||
"Ignoring Library INF due to only supporting type HOST_APPLICATION {0}".format(INF))
|
||||
continue
|
||||
|
||||
logging.critical(INF + " not in " + wsr_dsc_path)
|
||||
tc.LogStdError("{0} not in {1}".format(INF, wsr_dsc_path))
|
||||
overall_status = overall_status + 1
|
||||
|
||||
# If XML object exists, add result
|
||||
if overall_status != 0:
|
||||
tc.SetFailed("DscCompleteCheck {0} Failed. Errors {1}".format(
|
||||
wsr_dsc_path, overall_status), "CHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
@@ -1,12 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to confirm all INFs are listed in
|
||||
# the components section of package dsc
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Dsc Complete Check Test",
|
||||
"module": "DscCompleteCheck"
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
# Dsc Complete Check Plugin
|
||||
|
||||
This CiBuildPlugin scans all INF files from a package and confirms they are
|
||||
listed in the package level DSC file. The test considers it an error if any INF
|
||||
does not appear in the `Components` section of the package-level DSC (indicating
|
||||
that it would not be built if the package were built). This is critical because
|
||||
much of the CI infrastructure assumes that all modules will be listed in the DSC
|
||||
and compiled.
|
||||
|
||||
This test will ignore INFs in the following cases:
|
||||
|
||||
1. When MODULE_TYPE = HOST_APPLICATION
|
||||
2. When a Library instance **only** supports the HOST_APPLICATION environment
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin has a few configuration options to support the UEFI codebase.
|
||||
|
||||
``` yaml
|
||||
"DscCompleteCheck": {
|
||||
"DscPath": "", # Path to dsc from root of package
|
||||
"IgnoreInf": [] # Ignore INF if found in filesystem but not dsc
|
||||
}
|
||||
```
|
||||
|
||||
### DscPath
|
||||
|
||||
Path to DSC to consider platform dsc
|
||||
|
||||
### IgnoreInf
|
||||
|
||||
Ignore error if Inf file is not listed in DSC file
|
||||
@@ -1,311 +0,0 @@
|
||||
# @file EccCheck.py
|
||||
#
|
||||
# Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
|
||||
# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import re
|
||||
import csv
|
||||
import xml.dom.minidom
|
||||
from typing import List, Dict, Tuple
|
||||
import logging
|
||||
from io import StringIO
|
||||
from edk2toolext.environment import shell_environment
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
from edk2toollib.utility_functions import RunCmd
|
||||
|
||||
|
||||
class EccCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that finds the Ecc issues of newly added code in pull request.
|
||||
|
||||
Configuration options:
|
||||
"EccCheck": {
|
||||
"ExceptionList": [],
|
||||
"IgnoreFiles": []
|
||||
},
|
||||
"""
|
||||
|
||||
ReModifyFile = re.compile(r'[B-Q,S-Z]+[\d]*\t(.*)')
|
||||
FindModifyFile = re.compile(r'\+\+\+ b\/(.*)')
|
||||
LineScopePattern = (r'@@ -\d*\,*\d* \+\d*\,*\d* @@.*')
|
||||
LineNumRange = re.compile(r'@@ -\d*\,*\d* \+(\d*)\,*(\d*) @@.*')
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
"""
|
||||
return ("Check for efi coding style for " + packagename, packagename + ".EccCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the ci_build_plugin Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
workspace_path = Edk2pathObj.WorkspacePath
|
||||
basetools_path = environment.GetValue("EDK_TOOLS_PATH")
|
||||
python_path = os.path.join(basetools_path, "Source", "Python")
|
||||
env = shell_environment.GetEnvironment()
|
||||
env.set_shell_var('PYTHONPATH', python_path)
|
||||
env.set_shell_var('WORKSPACE', workspace_path)
|
||||
env.set_shell_var('PACKAGES_PATH', os.pathsep.join(Edk2pathObj.PackagePathList))
|
||||
self.ECC_PASS = True
|
||||
self.ApplyConfig(pkgconfig, workspace_path, basetools_path, packagename)
|
||||
modify_dir_list = self.GetModifyDir(packagename)
|
||||
patch = self.GetDiff(packagename)
|
||||
ecc_diff_range = self.GetDiffRange(patch, packagename, workspace_path)
|
||||
self.GenerateEccReport(modify_dir_list, ecc_diff_range, workspace_path, basetools_path)
|
||||
ecc_log = os.path.join(workspace_path, "Ecc.log")
|
||||
self.RevertCode()
|
||||
if self.ECC_PASS:
|
||||
tc.SetSuccess()
|
||||
self.RemoveFile(ecc_log)
|
||||
return 0
|
||||
else:
|
||||
with open(ecc_log, encoding='utf8') as output:
|
||||
ecc_output = output.readlines()
|
||||
for line in ecc_output:
|
||||
logging.error(line.strip())
|
||||
self.RemoveFile(ecc_log)
|
||||
tc.SetFailed("EccCheck failed for {0}".format(packagename), "Ecc detected issues")
|
||||
return 1
|
||||
|
||||
def RevertCode(self) -> None:
|
||||
submoudle_params = "submodule update --init"
|
||||
RunCmd("git", submoudle_params)
|
||||
reset_params = "reset HEAD --hard"
|
||||
RunCmd("git", reset_params)
|
||||
|
||||
def GetDiff(self, pkg: str) -> List[str]:
|
||||
return_buffer = StringIO()
|
||||
params = "diff --unified=0 origin/master HEAD"
|
||||
RunCmd("git", params, outstream=return_buffer)
|
||||
p = return_buffer.getvalue().strip()
|
||||
patch = p.split("\n")
|
||||
return_buffer.close()
|
||||
|
||||
return patch
|
||||
|
||||
def RemoveFile(self, file: str) -> None:
|
||||
if os.path.exists(file):
|
||||
os.remove(file)
|
||||
return
|
||||
|
||||
def GetModifyDir(self, pkg: str) -> List[str]:
|
||||
return_buffer = StringIO()
|
||||
params = "diff --name-status" + ' HEAD' + ' origin/master'
|
||||
RunCmd("git", params, outstream=return_buffer)
|
||||
p1 = return_buffer.getvalue().strip()
|
||||
dir_list = p1.split("\n")
|
||||
return_buffer.close()
|
||||
modify_dir_list = []
|
||||
for modify_dir in dir_list:
|
||||
file_path = self.ReModifyFile.findall(modify_dir)
|
||||
if file_path:
|
||||
file_dir = os.path.dirname(file_path[0])
|
||||
else:
|
||||
continue
|
||||
if pkg in file_dir and file_dir != pkg:
|
||||
modify_dir_list.append('%s' % file_dir)
|
||||
else:
|
||||
continue
|
||||
|
||||
modify_dir_list = list(set(modify_dir_list))
|
||||
return modify_dir_list
|
||||
|
||||
def GetDiffRange(self, patch_diff: List[str], pkg: str, workingdir: str) -> Dict[str, List[Tuple[int, int]]]:
|
||||
IsDelete = True
|
||||
StartCheck = False
|
||||
range_directory: Dict[str, List[Tuple[int, int]]] = {}
|
||||
for line in patch_diff:
|
||||
modify_file = self.FindModifyFile.findall(line)
|
||||
if modify_file and pkg in modify_file[0] and not StartCheck and os.path.isfile(modify_file[0]):
|
||||
modify_file_comment_dic = self.GetCommentRange(modify_file[0], workingdir)
|
||||
IsDelete = False
|
||||
StartCheck = True
|
||||
modify_file_dic = modify_file[0]
|
||||
modify_file_dic = modify_file_dic.replace("/", os.sep)
|
||||
range_directory[modify_file_dic] = []
|
||||
elif line.startswith('--- '):
|
||||
StartCheck = False
|
||||
elif re.match(self.LineScopePattern, line, re.I) and not IsDelete and StartCheck:
|
||||
start_line = self.LineNumRange.search(line).group(1)
|
||||
line_range = self.LineNumRange.search(line).group(2)
|
||||
if not line_range:
|
||||
line_range = '1'
|
||||
range_directory[modify_file_dic].append((int(start_line), int(start_line) + int(line_range) - 1))
|
||||
for i in modify_file_comment_dic:
|
||||
if int(i[0]) <= int(start_line) <= int(i[1]):
|
||||
range_directory[modify_file_dic].append(i)
|
||||
return range_directory
|
||||
|
||||
def GetCommentRange(self, modify_file: str, workingdir: str) -> List[Tuple[int, int]]:
|
||||
modify_file_path = os.path.join(workingdir, modify_file)
|
||||
with open(modify_file_path) as f:
|
||||
line_no = 1
|
||||
comment_range: List[Tuple[int, int]] = []
|
||||
Start = False
|
||||
for line in f:
|
||||
if line.startswith('/**'):
|
||||
start_no = line_no
|
||||
Start = True
|
||||
if line.startswith('**/') and Start:
|
||||
end_no = line_no
|
||||
Start = False
|
||||
comment_range.append((int(start_no), int(end_no)))
|
||||
line_no += 1
|
||||
|
||||
if comment_range and comment_range[0][0] == 1:
|
||||
del comment_range[0]
|
||||
return comment_range
|
||||
|
||||
def GenerateEccReport(self, modify_dir_list: List[str], ecc_diff_range: Dict[str, List[Tuple[int, int]]],
|
||||
workspace_path: str, basetools_path: str) -> None:
|
||||
ecc_need = False
|
||||
ecc_run = True
|
||||
config = os.path.join(basetools_path, "Source", "Python", "Ecc", "config.ini")
|
||||
exception = os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml")
|
||||
report = os.path.join(workspace_path, "Ecc.csv")
|
||||
for modify_dir in modify_dir_list:
|
||||
target = os.path.join(workspace_path, modify_dir)
|
||||
logging.info('Run ECC tool for the commit in %s' % modify_dir)
|
||||
ecc_need = True
|
||||
ecc_params = "-c {0} -e {1} -t {2} -r {3}".format(config, exception, target, report)
|
||||
return_code = RunCmd("Ecc", ecc_params, workingdir=workspace_path)
|
||||
if return_code != 0:
|
||||
ecc_run = False
|
||||
break
|
||||
if not ecc_run:
|
||||
logging.error('Fail to run ECC tool')
|
||||
self.ParseEccReport(ecc_diff_range, workspace_path)
|
||||
|
||||
if not ecc_need:
|
||||
logging.info("Doesn't need run ECC check")
|
||||
|
||||
revert_params = "checkout -- {}".format(exception)
|
||||
RunCmd("git", revert_params)
|
||||
return
|
||||
|
||||
def ParseEccReport(self, ecc_diff_range: Dict[str, List[Tuple[int, int]]], workspace_path: str) -> None:
|
||||
ecc_log = os.path.join(workspace_path, "Ecc.log")
|
||||
ecc_csv = os.path.join(workspace_path, "Ecc.csv")
|
||||
row_lines = []
|
||||
ignore_error_code = self.GetIgnoreErrorCode()
|
||||
if os.path.exists(ecc_csv):
|
||||
with open(ecc_csv) as csv_file:
|
||||
reader = csv.reader(csv_file)
|
||||
for row in reader:
|
||||
for modify_file in ecc_diff_range:
|
||||
if modify_file in row[3]:
|
||||
for i in ecc_diff_range[modify_file]:
|
||||
line_no = int(row[4])
|
||||
if i[0] <= line_no <= i[1] and row[1] not in ignore_error_code:
|
||||
row[0] = '\nEFI coding style error'
|
||||
row[1] = 'Error code: ' + row[1]
|
||||
row[3] = 'file: ' + row[3]
|
||||
row[4] = 'Line number: ' + row[4]
|
||||
row_line = '\n *'.join(row)
|
||||
row_lines.append(row_line)
|
||||
break
|
||||
break
|
||||
if row_lines:
|
||||
self.ECC_PASS = False
|
||||
|
||||
with open(ecc_log, 'a') as log:
|
||||
all_line = '\n'.join(row_lines)
|
||||
all_line = all_line + '\n'
|
||||
log.writelines(all_line)
|
||||
return
|
||||
|
||||
def ApplyConfig(self, pkgconfig: Dict[str, List[str]], workspace_path: str, basetools_path: str, pkg: str) -> None:
|
||||
if "IgnoreFiles" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreFiles"]:
|
||||
a = os.path.join(workspace_path, pkg, a)
|
||||
a = a.replace(os.sep, "/")
|
||||
|
||||
logging.info("Ignoring Files {0}".format(a))
|
||||
if os.path.exists(a):
|
||||
if os.path.isfile(a):
|
||||
self.RemoveFile(a)
|
||||
elif os.path.isdir(a):
|
||||
shutil.rmtree(a)
|
||||
else:
|
||||
logging.error("EccCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore files".format(a))
|
||||
|
||||
if "ExceptionList" in pkgconfig:
|
||||
exception_list = pkgconfig["ExceptionList"]
|
||||
exception_xml = os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml")
|
||||
try:
|
||||
logging.info("Appending exceptions")
|
||||
self.AppendException(exception_list, exception_xml)
|
||||
except Exception as e:
|
||||
logging.error("Fail to apply exceptions")
|
||||
raise e
|
||||
return
|
||||
|
||||
def AppendException(self, exception_list: List[str], exception_xml: str) -> None:
|
||||
error_code_list = exception_list[::2]
|
||||
keyword_list = exception_list[1::2]
|
||||
dom_tree = xml.dom.minidom.parse(exception_xml)
|
||||
root_node = dom_tree.documentElement
|
||||
for error_code, keyword in zip(error_code_list, keyword_list):
|
||||
customer_node = dom_tree.createElement("Exception")
|
||||
keyword_node = dom_tree.createElement("KeyWord")
|
||||
keyword_node_text_value = dom_tree.createTextNode(keyword)
|
||||
keyword_node.appendChild(keyword_node_text_value)
|
||||
customer_node.appendChild(keyword_node)
|
||||
error_code_node = dom_tree.createElement("ErrorID")
|
||||
error_code_text_value = dom_tree.createTextNode(error_code)
|
||||
error_code_node.appendChild(error_code_text_value)
|
||||
customer_node.appendChild(error_code_node)
|
||||
root_node.appendChild(customer_node)
|
||||
with open(exception_xml, 'w') as f:
|
||||
dom_tree.writexml(f, indent='', addindent='', newl='\n', encoding='UTF-8')
|
||||
return
|
||||
|
||||
def GetIgnoreErrorCode(self) -> set:
|
||||
"""
|
||||
Below are kinds of error code that are accurate in ecc scanning of edk2 level.
|
||||
But EccCheck plugin is partial scanning so they are always false positive issues.
|
||||
The mapping relationship of error code and error message is listed BaseTools/Sourc/Python/Ecc/EccToolError.py
|
||||
"""
|
||||
ignore_error_code = {
|
||||
"10000",
|
||||
"10001",
|
||||
"10002",
|
||||
"10003",
|
||||
"10004",
|
||||
"10005",
|
||||
"10006",
|
||||
"10007",
|
||||
"10008",
|
||||
"10009",
|
||||
"10010",
|
||||
"10011",
|
||||
"10012",
|
||||
"10013",
|
||||
"10015",
|
||||
"10016",
|
||||
"10017",
|
||||
"10022",
|
||||
}
|
||||
return ignore_error_code
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check Ecc issues
|
||||
#
|
||||
# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "EccCheck Test",
|
||||
"module": "EccCheck"
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
# EFI Coding style Check Plugin
|
||||
|
||||
This CiBuildPlugin finds the Ecc issues of newly added code in pull request.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin can be configured to ignore certain files and issues.
|
||||
|
||||
"EccCheck": {
|
||||
"ExceptionList": [],
|
||||
"IgnoreFiles": []
|
||||
},
|
||||
"""
|
||||
|
||||
OPTIONAL List of file to ignore.
|
||||
@@ -1,251 +0,0 @@
|
||||
# @file GuidCheck.py
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
import logging
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toollib.uefi.edk2.guid_list import GuidList
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
|
||||
class GuidCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that scans the code tree and looks for duplicate guids
|
||||
from the package being tested.
|
||||
|
||||
Configuration options:
|
||||
"GuidCheck": {
|
||||
"IgnoreGuidName": [], # provide in format guidname=guidvalue or just guidname
|
||||
"IgnoreGuidValue": [],
|
||||
"IgnoreFoldersAndFiles": [],
|
||||
"IgnoreDuplicates": [] # Provide in format guidname=guidname=guidname...
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
"""
|
||||
return ("Confirm GUIDs are unique in " + packagename, packagename + ".GuidCheck")
|
||||
|
||||
def _FindConflictingGuidValues(self, guidlist: list) -> list:
|
||||
""" Find all duplicate guids by guid value and report them as errors
|
||||
"""
|
||||
# Sort the list by guid
|
||||
guidsorted = sorted(
|
||||
guidlist, key=lambda x: x.guid.upper(), reverse=True)
|
||||
|
||||
previous = None # Store previous entry for comparison
|
||||
error = None
|
||||
errors = []
|
||||
for index in range(len(guidsorted)):
|
||||
i = guidsorted[index]
|
||||
if(previous is not None):
|
||||
if i.guid == previous.guid: # Error
|
||||
if(error is None):
|
||||
# Catch errors with more than 1 conflict
|
||||
error = ErrorEntry("guid")
|
||||
error.entries.append(previous)
|
||||
errors.append(error)
|
||||
error.entries.append(i)
|
||||
else:
|
||||
# no match. clear error
|
||||
error = None
|
||||
previous = i
|
||||
return errors
|
||||
|
||||
def _FindConflictingGuidNames(self, guidlist: list) -> list:
|
||||
""" Find all duplicate guids by name and if they are not all
|
||||
from inf files report them as errors. It is ok to have
|
||||
BASE_NAME duplication.
|
||||
|
||||
Is this useful? It would catch two same named guids in dec file
|
||||
that resolve to different values.
|
||||
"""
|
||||
# Sort the list by guid
|
||||
namesorted = sorted(guidlist, key=lambda x: x.name.upper())
|
||||
|
||||
previous = None # Store previous entry for comparison
|
||||
error = None
|
||||
errors = []
|
||||
for index in range(len(namesorted)):
|
||||
i = namesorted[index]
|
||||
if(previous is not None):
|
||||
# If name matches
|
||||
if i.name == previous.name:
|
||||
if(error is None):
|
||||
# Catch errors with more than 1 conflict
|
||||
error = ErrorEntry("name")
|
||||
error.entries.append(previous)
|
||||
errors.append(error)
|
||||
error.entries.append(i)
|
||||
else:
|
||||
# no match. clear error
|
||||
error = None
|
||||
previous = i
|
||||
|
||||
# Loop thru and remove any errors where all files are infs as it is ok if
|
||||
# they have the same inf base name.
|
||||
for e in errors[:]:
|
||||
if len( [en for en in e.entries if not en.absfilepath.lower().endswith(".inf")]) == 0:
|
||||
errors.remove(e)
|
||||
|
||||
return errors
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the MuBuild Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
Errors = []
|
||||
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(
|
||||
packagename)
|
||||
|
||||
if abs_pkg_path is None:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No package {0}".format(packagename))
|
||||
return -1
|
||||
|
||||
All_Ignores = ["/Build", "/Conf"]
|
||||
# Parse the config for other ignores
|
||||
if "IgnoreFoldersAndFiles" in pkgconfig:
|
||||
All_Ignores.extend(pkgconfig["IgnoreFoldersAndFiles"])
|
||||
|
||||
# Parse the workspace for all GUIDs
|
||||
gs = GuidList.guidlist_from_filesystem(
|
||||
Edk2pathObj.WorkspacePath, ignore_lines=All_Ignores)
|
||||
|
||||
# Remove ignored guidvalue
|
||||
if "IgnoreGuidValue" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreGuidValue"]:
|
||||
try:
|
||||
tc.LogStdOut("Ignoring Guid {0}".format(a.upper()))
|
||||
for b in gs[:]:
|
||||
if b.guid == a.upper():
|
||||
gs.remove(b)
|
||||
except:
|
||||
tc.LogStdError("GuidCheck.IgnoreGuid -> {0} not found. Invalid ignore guid".format(a.upper()))
|
||||
logging.info("GuidCheck.IgnoreGuid -> {0} not found. Invalid ignore guid".format(a.upper()))
|
||||
|
||||
# Remove ignored guidname
|
||||
if "IgnoreGuidName" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreGuidName"]:
|
||||
entry = a.split("=")
|
||||
if(len(entry) > 2):
|
||||
tc.LogStdError("GuidCheck.IgnoreGuidName -> {0} Invalid Format.".format(a))
|
||||
logging.info("GuidCheck.IgnoreGuidName -> {0} Invalid Format.".format(a))
|
||||
continue
|
||||
try:
|
||||
tc.LogStdOut("Ignoring Guid {0}".format(a))
|
||||
for b in gs[:]:
|
||||
if b.name == entry[0]:
|
||||
if(len(entry) == 1):
|
||||
gs.remove(b)
|
||||
elif(len(entry) == 2 and b.guid.upper() == entry[1].upper()):
|
||||
gs.remove(b)
|
||||
else:
|
||||
c.LogStdError("GuidCheck.IgnoreGuidName -> {0} incomplete match. Invalid ignore guid".format(a))
|
||||
|
||||
except:
|
||||
tc.LogStdError("GuidCheck.IgnoreGuidName -> {0} not found. Invalid ignore name".format(a))
|
||||
logging.info("GuidCheck.IgnoreGuidName -> {0} not found. Invalid ignore name".format(a))
|
||||
|
||||
# Find conflicting Guid Values
|
||||
Errors.extend(self._FindConflictingGuidValues(gs))
|
||||
|
||||
# Check if there are expected duplicates and remove it from the error list
|
||||
if "IgnoreDuplicates" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreDuplicates"]:
|
||||
names = a.split("=")
|
||||
if len(names) < 2:
|
||||
tc.LogStdError("GuidCheck.IgnoreDuplicates -> {0} invalid format".format(a))
|
||||
logging.info("GuidCheck.IgnoreDuplicates -> {0} invalid format".format(a))
|
||||
continue
|
||||
|
||||
for b in Errors[:]:
|
||||
if b.type != "guid":
|
||||
continue
|
||||
## Make a list of the names that are not in the names list. If there
|
||||
## are any in the list then this error should not be ignored.
|
||||
t = [x for x in b.entries if x.name not in names]
|
||||
if(len(t) == len(b.entries)):
|
||||
## did not apply to any entry
|
||||
continue
|
||||
elif(len(t) == 0):
|
||||
## full match - ignore duplicate
|
||||
tc.LogStdOut("GuidCheck.IgnoreDuplicates -> {0}".format(a))
|
||||
Errors.remove(b)
|
||||
elif(len(t) < len(b.entries)):
|
||||
## partial match
|
||||
tc.LogStdOut("GuidCheck.IgnoreDuplicates -> {0} incomplete match".format(a))
|
||||
logging.info("GuidCheck.IgnoreDuplicates -> {0} incomplete match".format(a))
|
||||
else:
|
||||
tc.LogStdOut("GuidCheck.IgnoreDuplicates -> {0} unknown error.".format(a))
|
||||
logging.info("GuidCheck.IgnoreDuplicates -> {0} unknown error".format(a))
|
||||
|
||||
|
||||
|
||||
# Find conflicting Guid Names
|
||||
Errors.extend(self._FindConflictingGuidNames(gs))
|
||||
|
||||
# Log errors for anything within the package under test
|
||||
for er in Errors[:]:
|
||||
InMyPackage = False
|
||||
for a in er.entries:
|
||||
if abs_pkg_path in a.absfilepath:
|
||||
InMyPackage = True
|
||||
break
|
||||
if(not InMyPackage):
|
||||
Errors.remove(er)
|
||||
else:
|
||||
logging.error(str(er))
|
||||
tc.LogStdError(str(er))
|
||||
|
||||
# add result to test case
|
||||
overall_status = len(Errors)
|
||||
if overall_status != 0:
|
||||
tc.SetFailed("GuidCheck {0} Failed. Errors {1}".format(
|
||||
packagename, overall_status), "CHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
|
||||
|
||||
class ErrorEntry():
|
||||
""" Custom/private class for reporting errors in the GuidList
|
||||
"""
|
||||
|
||||
def __init__(self, errortype):
|
||||
self.type = errortype # 'guid' or 'name' depending on error type
|
||||
self.entries = [] # GuidListEntry that are in error condition
|
||||
|
||||
def __str__(self):
|
||||
a = f"Error Duplicate {self.type}: "
|
||||
if(self.type == "guid"):
|
||||
a += f" {self.entries[0].guid}"
|
||||
elif(self.type == "name"):
|
||||
a += f" {self.entries[0].name}"
|
||||
|
||||
a += f" ({len(self.entries)})\n"
|
||||
|
||||
for e in self.entries:
|
||||
a += "\t" + str(e) + "\n"
|
||||
return a
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check guid uniqueness
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Guid Check Test",
|
||||
"module": "GuidCheck"
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
# Guid Check Plugin
|
||||
|
||||
This CiBuildPlugin scans all the files in a code tree to find all the GUID
|
||||
definitions. After collection it will then look for duplication in the package
|
||||
under test. Uniqueness of all GUIDs are critical within the UEFI environment.
|
||||
Duplication can cause numerous issues including locating the wrong data
|
||||
structure, calling the wrong function, or decoding the wrong data members.
|
||||
|
||||
Currently Scanned:
|
||||
|
||||
* INF files are scanned for there Module guid
|
||||
* DEC files are scanned for all of their Protocols, PPIs, and Guids as well as
|
||||
the one package GUID.
|
||||
|
||||
Any GUID value being equal to two names or even just defined in two files is
|
||||
considered an error unless in the ignore list.
|
||||
|
||||
Any GUID name that is found more than once is an error unless all occurrences
|
||||
are Module GUIDs. Since the Module GUID is assigned to the Module name it is
|
||||
common to have numerous versions of the same module named the same.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin has numerous configuration options to support the UEFI codebase.
|
||||
|
||||
``` yaml
|
||||
"GuidCheck": {
|
||||
"IgnoreGuidName": [],
|
||||
"IgnoreGuidValue": [],
|
||||
"IgnoreFoldersAndFiles": [],
|
||||
"IgnoreDuplicates": []
|
||||
}
|
||||
```
|
||||
|
||||
### IgnoreGuidName
|
||||
|
||||
This list allows strings in two formats.
|
||||
|
||||
* _GuidName_
|
||||
* This will remove any entry with this GuidName from the list of GUIDs
|
||||
therefore ignoring any error associated with this name.
|
||||
* _GuidName=GuidValue_
|
||||
* This will also ignore the GUID by name but only if the value equals the
|
||||
GuidValue.
|
||||
* GuidValue should be in registry format.
|
||||
* This is the suggested format to use as it will limit the ignore to only the
|
||||
defined case.
|
||||
|
||||
### IgnoreGuidValue
|
||||
|
||||
This list allows strings in guid registry format _GuidValue_.
|
||||
|
||||
* This will remove any entry with this GuidValue from the list of GUIDs
|
||||
therefore ignoring any error associated with this value.
|
||||
* GuidValue must be in registry format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
|
||||
### IgnoreFoldersAndFiles
|
||||
|
||||
This supports .gitignore file and folder matching strings including wildcards
|
||||
|
||||
* Any folder or file ignored will not be parsed and therefore any GUID defined
|
||||
will be ignored.
|
||||
* The plugin will always ignores the following ["/Build", "/Conf"]
|
||||
|
||||
### IgnoreDuplicates
|
||||
|
||||
This supports strings in the format of _GuidName_=_GuidName_=_GuidName_
|
||||
|
||||
* For the error with the GuidNames to be ignored the list must match completely
|
||||
with what is found during the code scan.
|
||||
* For example if there are two GUIDs that are by design equal within the code
|
||||
tree then it should be _GuidName_=_GuidName_
|
||||
* If instead there are three GUIDs then it must be
|
||||
_GuidName_=_GuidName_=_GuidName_
|
||||
* This is the best ignore list to use because it is the most strict and will
|
||||
catch new problems when new conflicts are introduced.
|
||||
* There are numerous places in the UEFI specification in which two GUID names
|
||||
are assigned the same value. These names should be set in this ignore list so
|
||||
that they don't cause an error but any additional duplication would still be
|
||||
caught.
|
||||
@@ -1,149 +0,0 @@
|
||||
# @file HostUnitTestCompilerPlugin.py
|
||||
##
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toolext.environment.uefi_build import UefiBuilder
|
||||
from edk2toolext import edk2_logging
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
from edk2toollib.utility_functions import GetHostInfo
|
||||
|
||||
|
||||
class HostUnitTestCompilerPlugin(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that compiles the dsc for host based unit test apps.
|
||||
An IUefiBuildPlugin may be attached to this plugin that will run the
|
||||
unit tests and collect the results after successful compilation.
|
||||
|
||||
Configuration options:
|
||||
"HostUnitTestCompilerPlugin": {
|
||||
"DscPath": "<path to dsc from root of pkg>"
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
"""
|
||||
num,types = self.__GetHostUnitTestArch(environment)
|
||||
types = types.replace(" ", "_")
|
||||
|
||||
return ("Compile and Run Host-Based UnitTests for " + packagename + " on arch " + types,
|
||||
packagename + ".HostUnitTestCompiler." + types)
|
||||
|
||||
def RunsOnTargetList(self):
|
||||
return ["NOOPT"]
|
||||
|
||||
#
|
||||
# Find the intersection of application types that can run on this host
|
||||
# and the TARGET_ARCH being build in this request.
|
||||
#
|
||||
# return tuple with (number of UEFI arch types, space separated string)
|
||||
def __GetHostUnitTestArch(self, environment):
|
||||
requested = environment.GetValue("TARGET_ARCH").split(' ')
|
||||
host = []
|
||||
if GetHostInfo().arch == 'x86':
|
||||
#assume 64bit can handle 64 and 32
|
||||
#assume 32bit can only handle 32
|
||||
## change once IA32 issues resolved host.append("IA32")
|
||||
if GetHostInfo().bit == '64':
|
||||
host.append("X64")
|
||||
elif GetHostInfo().arch == 'ARM':
|
||||
if GetHostInfo().bit == '64':
|
||||
host.append("AARCH64")
|
||||
elif GetHostInfo().bit == '32':
|
||||
host.append("ARM")
|
||||
|
||||
willrun = set(requested) & set(host)
|
||||
return (len(willrun), " ".join(willrun))
|
||||
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the ICiBuildPlugin Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
self._env = environment
|
||||
environment.SetValue("CI_BUILD_TYPE", "host_unit_test", "Set in HostUnitTestCompilerPlugin")
|
||||
|
||||
# Parse the config for required DscPath element
|
||||
if "DscPath" not in pkgconfig:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("DscPath not found in config file. Nothing to compile for HostBasedUnitTests.")
|
||||
return -1
|
||||
|
||||
AP = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)
|
||||
|
||||
APDSC = os.path.join(AP, pkgconfig["DscPath"].strip())
|
||||
AP_Path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(APDSC)
|
||||
if AP is None or AP_Path is None or not os.path.isfile(APDSC):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("Package HostBasedUnitTest Dsc not found.")
|
||||
return -1
|
||||
|
||||
logging.info("Building {0}".format(AP_Path))
|
||||
self._env.SetValue("ACTIVE_PLATFORM", AP_Path, "Set in Compiler Plugin")
|
||||
num, RUNNABLE_ARCHITECTURES = self.__GetHostUnitTestArch(environment)
|
||||
if(num == 0):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No host architecture compatibility")
|
||||
return -1
|
||||
|
||||
if not environment.SetValue("TARGET_ARCH",
|
||||
RUNNABLE_ARCHITECTURES,
|
||||
"Update Target Arch based on Host Support"):
|
||||
#use AllowOverride function since this is a controlled attempt to change
|
||||
environment.AllowOverride("TARGET_ARCH")
|
||||
if not environment.SetValue("TARGET_ARCH",
|
||||
RUNNABLE_ARCHITECTURES,
|
||||
"Update Target Arch based on Host Support"):
|
||||
raise RuntimeError("Can't Change TARGET_ARCH as required")
|
||||
|
||||
# Parse DSC to check for SUPPORTED_ARCHITECTURES
|
||||
dp = DscParser()
|
||||
dp.SetBaseAbsPath(Edk2pathObj.WorkspacePath)
|
||||
dp.SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
dp.ParseFile(AP_Path)
|
||||
if "SUPPORTED_ARCHITECTURES" in dp.LocalVars:
|
||||
SUPPORTED_ARCHITECTURES = dp.LocalVars["SUPPORTED_ARCHITECTURES"].split('|')
|
||||
TARGET_ARCHITECTURES = environment.GetValue("TARGET_ARCH").split(' ')
|
||||
|
||||
# Skip if there is no intersection between SUPPORTED_ARCHITECTURES and TARGET_ARCHITECTURES
|
||||
if len(set(SUPPORTED_ARCHITECTURES) & set(TARGET_ARCHITECTURES)) == 0:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No supported architecutres to build for host unit tests")
|
||||
return -1
|
||||
|
||||
uefiBuilder = UefiBuilder()
|
||||
# do all the steps
|
||||
# WorkSpace, PackagesPath, PInHelper, PInManager
|
||||
ret = uefiBuilder.Go(Edk2pathObj.WorkspacePath, os.pathsep.join(Edk2pathObj.PackagePathList), PLMHelper, PLM)
|
||||
if ret != 0: # failure:
|
||||
tc.SetFailed("Compile failed for {0}".format(packagename), "Compile_FAILED")
|
||||
tc.LogStdError("{0} Compile failed with error code {1} ".format(AP_Path, ret))
|
||||
return 1
|
||||
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return 0
|
||||
@@ -1,12 +0,0 @@
|
||||
##
|
||||
# CiBuildPlugin used to build anything that identifies
|
||||
# as a unit test.
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "host-based-test",
|
||||
"name": "Host Unit Test Compiler Plugin",
|
||||
"module": "HostUnitTestCompilerPlugin"
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
# Host UnitTest Compiler Plugin
|
||||
|
||||
A CiBuildPlugin that compiles the dsc for host based unit test apps.
|
||||
An IUefiBuildPlugin may be attached to this plugin that will run the unit tests and collect the results after successful compilation.
|
||||
|
||||
## Configuration
|
||||
|
||||
The package relative path of the DSC file to build.
|
||||
|
||||
``` yaml
|
||||
"HostUnitTestCompilerPlugin": {
|
||||
"DscPath": "<path to dsc from root of pkg>"
|
||||
}
|
||||
```
|
||||
|
||||
### DscPath
|
||||
|
||||
Package relative path to the DSC file to build.
|
||||
|
||||
## Copyright
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
# @file HostUnitTestDscCompleteCheck.py
|
||||
#
|
||||
# This is a copy of DscCompleteCheck with different filtering logic.
|
||||
# It should be discussed if this should be one plugin
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
import logging
|
||||
import os
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser
|
||||
from edk2toollib.uefi.edk2.parsers.inf_parser import InfParser
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
|
||||
class HostUnitTestDscCompleteCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that scans the package Host Unit Test dsc file and confirms all Host application modules (inf files) are
|
||||
listed in the components sections.
|
||||
|
||||
Configuration options:
|
||||
"HostUnitTestDscCompleteCheck": {
|
||||
"DscPath": "", # Path to Host based unit test DSC file
|
||||
"IgnoreInf": [] # Ignore INF if found in filesystem but not dsc
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
"""
|
||||
return ("Check the " + packagename + " Host Unit Test DSC for a being complete", packagename + ".HostUnitTestDscCompleteCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the MuBuild Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - VarDict containing the shell environment Build Vars
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
overall_status = 0
|
||||
|
||||
# Parse the config for required DscPath element
|
||||
if "DscPath" not in pkgconfig:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError(
|
||||
"DscPath not found in config file. Nothing to check.")
|
||||
return -1
|
||||
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(
|
||||
packagename)
|
||||
abs_dsc_path = os.path.join(abs_pkg_path, pkgconfig["DscPath"].strip())
|
||||
wsr_dsc_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(
|
||||
abs_dsc_path)
|
||||
|
||||
if abs_dsc_path is None or wsr_dsc_path == "" or not os.path.isfile(abs_dsc_path):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("Package Host Unit Test Dsc not found")
|
||||
return 0
|
||||
|
||||
# Get INF Files
|
||||
INFFiles = self.WalkDirectoryForExtension([".inf"], abs_pkg_path)
|
||||
INFFiles = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(
|
||||
x) for x in INFFiles] # make edk2relative path so can compare with DSC
|
||||
|
||||
# remove ignores
|
||||
|
||||
if "IgnoreInf" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreInf"]:
|
||||
a = a.replace(os.sep, "/")
|
||||
try:
|
||||
tc.LogStdOut("Ignoring INF {0}".format(a))
|
||||
INFFiles.remove(a)
|
||||
except:
|
||||
tc.LogStdError(
|
||||
"HostUnitTestDscCompleteCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
logging.info(
|
||||
"HostUnitTestDscCompleteCheck.IgnoreInf -> {0} not found in filesystem. Invalid ignore file".format(a))
|
||||
|
||||
# DSC Parser
|
||||
dp = DscParser()
|
||||
dp.SetBaseAbsPath(Edk2pathObj.WorkspacePath)
|
||||
dp.SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
dp.SetInputVars(environment.GetAllBuildKeyValues())
|
||||
dp.ParseFile(wsr_dsc_path)
|
||||
|
||||
# Check if INF in component section
|
||||
for INF in INFFiles:
|
||||
if not any(INF.strip() in x for x in dp.ThreeMods) and \
|
||||
not any(INF.strip() in x for x in dp.SixMods) and \
|
||||
not any(INF.strip() in x for x in dp.OtherMods):
|
||||
|
||||
infp = InfParser().SetBaseAbsPath(Edk2pathObj.WorkspacePath)
|
||||
infp.SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
infp.ParseFile(INF)
|
||||
if("MODULE_TYPE" not in infp.Dict):
|
||||
tc.LogStdOut(
|
||||
"Ignoring INF. Missing key for MODULE_TYPE {0}".format(INF))
|
||||
continue
|
||||
|
||||
if(infp.Dict["MODULE_TYPE"] == "HOST_APPLICATION"):
|
||||
# should compile test a library that is declared type HOST_APPLICATION
|
||||
pass
|
||||
|
||||
elif len(infp.SupportedPhases) > 0 and \
|
||||
"HOST_APPLICATION" in infp.SupportedPhases:
|
||||
# should compile test a library that supports HOST_APPLICATION but
|
||||
# require it to be an explicit opt-in
|
||||
pass
|
||||
|
||||
else:
|
||||
tc.LogStdOut(
|
||||
"Ignoring INF. MODULE_TYPE or suppored phases not HOST_APPLICATION {0}".format(INF))
|
||||
continue
|
||||
|
||||
logging.critical(INF + " not in " + wsr_dsc_path)
|
||||
tc.LogStdError("{0} not in {1}".format(INF, wsr_dsc_path))
|
||||
overall_status = overall_status + 1
|
||||
|
||||
# If XML object exists, add result
|
||||
if overall_status != 0:
|
||||
tc.SetFailed("HostUnitTestDscCompleteCheck {0} Failed. Errors {1}".format(
|
||||
wsr_dsc_path, overall_status), "CHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
@@ -1,12 +0,0 @@
|
||||
##
|
||||
# CiBuildPlugin used to confirm all INFs are listed in
|
||||
# the components section of package dsc
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "host-based-test",
|
||||
"name": "Host Unit Test Dsc Complete Check Test",
|
||||
"module": "HostUnitTestDscCompleteCheck"
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
# Host Unit Test Dsc Complete Check Plugin
|
||||
|
||||
This CiBuildPlugin scans all INF files from a package for those related to host
|
||||
based unit tests confirms they are listed in the unit test DSC file for the package.
|
||||
The test considers it an error if any INF meeting the requirements does not appear
|
||||
in the `Components` section of the unit test DSC. This is critical because
|
||||
much of the CI infrastructure assumes that modules will be listed in the DSC
|
||||
and compiled.
|
||||
|
||||
This test will only require INFs in the following cases:
|
||||
|
||||
1. When MODULE_TYPE = HOST_APPLICATION
|
||||
2. When a Library instance supports the HOST_APPLICATION environment
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin has a few configuration options to support the UEFI codebase.
|
||||
|
||||
``` yaml
|
||||
"HostUnitTestDscCompleteCheck": {
|
||||
"DscPath": "", # Path to Host based unit test DSC file
|
||||
"IgnoreInf": [] # Ignore INF if found in filesystem but not dsc
|
||||
}
|
||||
```
|
||||
|
||||
### DscPath
|
||||
|
||||
Path to DSC to consider platform dsc
|
||||
|
||||
### IgnoreInf
|
||||
|
||||
Ignore error if Inf file is not listed in DSC file
|
||||
@@ -1,153 +0,0 @@
|
||||
# @file LibraryClassCheck.py
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
import logging
|
||||
import os
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toollib.uefi.edk2.parsers.dec_parser import DecParser
|
||||
from edk2toollib.uefi.edk2.parsers.inf_parser import InfParser
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
|
||||
|
||||
class LibraryClassCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that scans the code tree and library classes for undeclared
|
||||
files
|
||||
|
||||
Configuration options:
|
||||
"LibraryClassCheck": {
|
||||
IgnoreHeaderFile: [], # Ignore a file found on disk
|
||||
IgnoreLibraryClass: [] # Ignore a declaration found in dec file
|
||||
}
|
||||
"""
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
"""
|
||||
return ("Check library class declarations in " + packagename, packagename + ".LibraryClassCheck")
|
||||
|
||||
def __GetPkgDec(self, rootpath):
|
||||
try:
|
||||
allEntries = os.listdir(rootpath)
|
||||
for entry in allEntries:
|
||||
if entry.lower().endswith(".dec"):
|
||||
return(os.path.join(rootpath, entry))
|
||||
except Exception:
|
||||
logging.error("Unable to find DEC for package:{0}".format(rootpath))
|
||||
|
||||
return None
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the MuBuild Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
overall_status = 0
|
||||
LibraryClassIgnore = []
|
||||
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)
|
||||
abs_dec_path = self.__GetPkgDec(abs_pkg_path)
|
||||
wsr_dec_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(abs_dec_path)
|
||||
|
||||
if abs_dec_path is None or wsr_dec_path == "" or not os.path.isfile(abs_dec_path):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No DEC file {0} in package {1}".format(abs_dec_path, abs_pkg_path))
|
||||
return -1
|
||||
|
||||
# Get all include folders
|
||||
dec = DecParser()
|
||||
dec.SetBaseAbsPath(Edk2pathObj.WorkspacePath).SetPackagePaths(Edk2pathObj.PackagePathList)
|
||||
dec.ParseFile(wsr_dec_path)
|
||||
|
||||
AllHeaderFiles = []
|
||||
|
||||
for includepath in dec.IncludePaths:
|
||||
## Get all header files in the library folder
|
||||
AbsLibraryIncludePath = os.path.join(abs_pkg_path, includepath, "Library")
|
||||
if(not os.path.isdir(AbsLibraryIncludePath)):
|
||||
continue
|
||||
|
||||
hfiles = self.WalkDirectoryForExtension([".h"], AbsLibraryIncludePath)
|
||||
hfiles = [os.path.relpath(x,abs_pkg_path) for x in hfiles] # make package root relative path
|
||||
hfiles = [x.replace("\\", "/") for x in hfiles] # make package relative path
|
||||
|
||||
AllHeaderFiles.extend(hfiles)
|
||||
|
||||
if len(AllHeaderFiles) == 0:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError(f"No Library include folder in any Include path")
|
||||
return -1
|
||||
|
||||
# Remove ignored paths
|
||||
if "IgnoreHeaderFile" in pkgconfig:
|
||||
for a in pkgconfig["IgnoreHeaderFile"]:
|
||||
try:
|
||||
tc.LogStdOut("Ignoring Library Header File {0}".format(a))
|
||||
AllHeaderFiles.remove(a)
|
||||
except:
|
||||
tc.LogStdError("LibraryClassCheck.IgnoreHeaderFile -> {0} not found. Invalid Header File".format(a))
|
||||
logging.info("LibraryClassCheck.IgnoreHeaderFile -> {0} not found. Invalid Header File".format(a))
|
||||
|
||||
if "IgnoreLibraryClass" in pkgconfig:
|
||||
LibraryClassIgnore = pkgconfig["IgnoreLibraryClass"]
|
||||
|
||||
|
||||
## Attempt to find library classes
|
||||
for lcd in dec.LibraryClasses:
|
||||
## Check for correct file path separator
|
||||
if "\\" in lcd.path:
|
||||
tc.LogStdError("LibraryClassCheck.DecFilePathSeparator -> {0} invalid.".format(lcd.path))
|
||||
logging.error("LibraryClassCheck.DecFilePathSeparator -> {0} invalid.".format(lcd.path))
|
||||
overall_status += 1
|
||||
continue
|
||||
|
||||
if lcd.name in LibraryClassIgnore:
|
||||
tc.LogStdOut("Ignoring Library Class Name {0}".format(lcd.name))
|
||||
LibraryClassIgnore.remove(lcd.name)
|
||||
continue
|
||||
|
||||
logging.debug(f"Looking for Library Class {lcd.path}")
|
||||
try:
|
||||
AllHeaderFiles.remove(lcd.path)
|
||||
|
||||
except ValueError:
|
||||
tc.LogStdError(f"Library {lcd.name} with path {lcd.path} not found in package filesystem")
|
||||
logging.error(f"Library {lcd.name} with path {lcd.path} not found in package filesystem")
|
||||
overall_status += 1
|
||||
|
||||
## any remaining AllHeaderFiles are not described in DEC
|
||||
for h in AllHeaderFiles:
|
||||
tc.LogStdError(f"Library Header File {h} not declared in package DEC {wsr_dec_path}")
|
||||
logging.error(f"Library Header File {h} not declared in package DEC {wsr_dec_path}")
|
||||
overall_status += 1
|
||||
|
||||
## Warn about any invalid library class names in the ignore list
|
||||
for r in LibraryClassIgnore:
|
||||
tc.LogStdError("LibraryClassCheck.IgnoreLibraryClass -> {0} not found. Library Class not found".format(r))
|
||||
logging.info("LibraryClassCheck.IgnoreLibraryClass -> {0} not found. Library Class not found".format(r))
|
||||
|
||||
|
||||
# If XML object exists, add result
|
||||
if overall_status != 0:
|
||||
tc.SetFailed("LibraryClassCheck {0} Failed. Errors {1}".format(wsr_dec_path, overall_status), "CHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check that all library classes are declared correctly in dec file
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Library Class Check Test",
|
||||
"module": "LibraryClassCheck"
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
# Library Class Check Plugin
|
||||
|
||||
This CiBuildPlugin scans at all library header files found in the `Library`
|
||||
folders in all of the package's declared include directories and ensures that
|
||||
all files have a matching LibraryClass declaration in the DEC file for the
|
||||
package. Any missing declarations will cause a failure.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin has a few configuration options to support the UEFI codebase.
|
||||
|
||||
``` yaml
|
||||
"LibraryClassCheck": {
|
||||
IgnoreHeaderFile: [], # Ignore a file found on disk
|
||||
IgnoreLibraryClass: [] # Ignore a declaration found in dec file
|
||||
}
|
||||
```
|
||||
|
||||
### IgnoreHeaderFile
|
||||
|
||||
Ignore a file found on disk
|
||||
|
||||
### IgnoreLibraryClass
|
||||
|
||||
Ignore a declaration found in dec file
|
||||
@@ -1,115 +0,0 @@
|
||||
# @file LicenseCheck.py
|
||||
#
|
||||
# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
import os
|
||||
import logging
|
||||
import re
|
||||
from io import StringIO
|
||||
from typing import List, Tuple
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
from edk2toollib.utility_functions import RunCmd
|
||||
|
||||
|
||||
class LicenseCheck(ICiBuildPlugin):
|
||||
|
||||
"""
|
||||
A CiBuildPlugin to check the license for new added files.
|
||||
|
||||
Configuration options:
|
||||
"LicenseCheck": {
|
||||
"IgnoreFiles": []
|
||||
},
|
||||
"""
|
||||
|
||||
license_format_preflix = 'SPDX-License-Identifier'
|
||||
|
||||
bsd2_patent = 'BSD-2-Clause-Patent'
|
||||
|
||||
Readdedfileformat = re.compile(r'\+\+\+ b\/(.*)')
|
||||
|
||||
file_extension_list = [".c", ".h", ".inf", ".dsc", ".dec", ".py", ".bat", ".sh", ".uni", ".yaml",
|
||||
".fdf", ".inc", "yml", ".asm", ".asm16", ".asl", ".vfr", ".s", ".S", ".aslc",
|
||||
".nasm", ".nasmb", ".idf", ".Vfr", ".H"]
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
"""
|
||||
return ("Check for license for " + packagename, packagename + ".LicenseCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the ci_build_plugin Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
return_buffer = StringIO()
|
||||
params = "diff --unified=0 origin/master HEAD"
|
||||
RunCmd("git", params, outstream=return_buffer)
|
||||
p = return_buffer.getvalue().strip()
|
||||
patch = p.split("\n")
|
||||
return_buffer.close()
|
||||
|
||||
ignore_files = []
|
||||
if "IgnoreFiles" in pkgconfig:
|
||||
ignore_files = pkgconfig["IgnoreFiles"]
|
||||
|
||||
self.ok = True
|
||||
self.startcheck = False
|
||||
self.license = True
|
||||
self.all_file_pass = True
|
||||
count = len(patch)
|
||||
line_index = 0
|
||||
for line in patch:
|
||||
if line.startswith('--- /dev/null'):
|
||||
nextline = patch[line_index + 1]
|
||||
added_file = self.Readdedfileformat.search(nextline).group(1)
|
||||
added_file_extension = os.path.splitext(added_file)[1]
|
||||
if added_file_extension in self.file_extension_list and packagename in added_file:
|
||||
if (self.IsIgnoreFile(added_file, ignore_files)):
|
||||
line_index = line_index + 1
|
||||
continue
|
||||
self.startcheck = True
|
||||
self.license = False
|
||||
if self.startcheck and self.license_format_preflix in line:
|
||||
if self.bsd2_patent in line:
|
||||
self.license = True
|
||||
if line_index + 1 == count or patch[line_index + 1].startswith('diff --') and self.startcheck:
|
||||
if not self.license:
|
||||
self.all_file_pass = False
|
||||
error_message = "Invalid license in: " + added_file + " Hint: Only BSD-2-Clause-Patent is accepted."
|
||||
logging.error(error_message)
|
||||
self.startcheck = False
|
||||
self.license = True
|
||||
line_index = line_index + 1
|
||||
|
||||
if self.all_file_pass:
|
||||
tc.SetSuccess()
|
||||
return 0
|
||||
else:
|
||||
tc.SetFailed("License Check {0} Failed. ".format(packagename), "LICENSE_CHECK_FAILED")
|
||||
return 1
|
||||
|
||||
def IsIgnoreFile(self, file: str, ignore_files: List[str]) -> bool:
|
||||
for f in ignore_files:
|
||||
if f in file:
|
||||
return True
|
||||
return False
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check license issues for new added files
|
||||
#
|
||||
# Copyright (c) 2020, Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "License Check Test",
|
||||
"module": "LicenseCheck"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
# License Check Plugin
|
||||
|
||||
This CiBuildPlugin scans all new added files in a package to make sure code
|
||||
is contributed under BSD-2-Clause-Patent.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin can be configured to ignore certain files.
|
||||
|
||||
``` yaml
|
||||
"LicenseCheck": {
|
||||
"IgnoreFiles": []
|
||||
}
|
||||
```
|
||||
### IgnoreFiles
|
||||
|
||||
OPTIONAL List of file to ignore.
|
||||
@@ -1,127 +0,0 @@
|
||||
# Spell Check Plugin
|
||||
|
||||
This CiBuildPlugin scans all the files in a given package and checks for
|
||||
spelling errors.
|
||||
|
||||
This plugin requires NodeJs and cspell. If the plugin doesn't find its required
|
||||
tools then it will mark the test as skipped.
|
||||
|
||||
* NodeJS: https://nodejs.org/en/
|
||||
* cspell: https://www.npmjs.com/package/cspell
|
||||
* Src and doc available: https://github.com/streetsidesoftware/cspell
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin has a few configuration options to support the UEFI codebase.
|
||||
|
||||
``` yaml
|
||||
"SpellCheck": {
|
||||
"AuditOnly": False, # If True, log all errors and then mark as skipped
|
||||
"IgnoreFiles": [], # use gitignore syntax to ignore errors in matching files
|
||||
"ExtendWords": [], # words to extend to the dictionary for this package
|
||||
"IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore
|
||||
"AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
|
||||
}
|
||||
```
|
||||
|
||||
### AuditOnly
|
||||
|
||||
Boolean - Default is False.
|
||||
If True run the test in an Audit only mode which will log all errors but instead
|
||||
of failing the build it will set the test as skipped. This allows visibility
|
||||
into the failures without breaking the build.
|
||||
|
||||
### IgnoreFiles
|
||||
|
||||
This supports .gitignore file and folder matching strings including wildcards
|
||||
|
||||
* All files will be parsed regardless but then any spelling errors found within
|
||||
ignored files will not be reported as an error.
|
||||
* Errors in ignored files will still be output to the test results as
|
||||
informational comments.
|
||||
|
||||
### ExtendWords
|
||||
|
||||
This list allows words to be added to the dictionary for the spell checker when
|
||||
this package is tested. These follow the rules of the cspell config words field.
|
||||
|
||||
### IgnoreStandardPaths
|
||||
|
||||
This plugin by default will check the below standard paths. If the package
|
||||
would like to ignore any of them list that here.
|
||||
|
||||
```python
|
||||
[
|
||||
# C source
|
||||
"*.c",
|
||||
"*.h",
|
||||
|
||||
# Assembly files
|
||||
"*.nasm",
|
||||
"*.asm",
|
||||
"*.masm",
|
||||
"*.s",
|
||||
|
||||
# ACPI source language
|
||||
"*.asl",
|
||||
|
||||
# Edk2 build files
|
||||
"*.dsc", "*.dec", "*.fdf", "*.inf",
|
||||
|
||||
# Documentation files
|
||||
"*.md", "*.txt"
|
||||
]
|
||||
```
|
||||
|
||||
### AdditionalIncludePaths
|
||||
|
||||
If the package would to add additional path patterns to be included in
|
||||
spellchecking they can be defined here.
|
||||
|
||||
## Other configuration
|
||||
|
||||
In the cspell.base.json there are numerous other settings configured. There is
|
||||
no support to override these on a per package basis but future features could
|
||||
make this available. One interesting configuration option is `minWordLength`.
|
||||
Currently it is set to _5_ which means all 2,3, and 4 letter words will be
|
||||
ignored. This helps minimize the number of technical acronyms, register names,
|
||||
and other UEFI specific values that must be ignored.
|
||||
|
||||
## False positives
|
||||
|
||||
The cspell dictionary is not perfect and there are cases where technical words
|
||||
or acronyms are not found in the dictionary. There are three ways to resolve
|
||||
false positives and the choice for which method should be based on how broadly
|
||||
the word should be accepted.
|
||||
|
||||
### CSpell Base Config file
|
||||
|
||||
If the change should apply to all UEFI code and documentation then it should be
|
||||
added to the base config file `words` section. The base config file is adjacent
|
||||
to this file and titled `cspell.base.json`. This is a list of accepted words
|
||||
for all spell checking operations on all packages.
|
||||
|
||||
### Package Config
|
||||
|
||||
In the package `*.ci.yaml` file there is a `SpellCheck` config section. This
|
||||
section allows files to be ignored as well as words that should be considered
|
||||
valid for all files within this package. Add the desired words to the
|
||||
"ExtendedWords" member.
|
||||
|
||||
### In-line File
|
||||
|
||||
CSpell supports numerous methods to annotate your files to ignore words,
|
||||
sections, etc. This can be found in CSpell documentation. Suggestion here is
|
||||
to use a c-style comment at the top of the file to add words that should be
|
||||
ignored just for this file. Obviously this has the highest maintenance cost so
|
||||
it should only be used for file unique words.
|
||||
|
||||
``` c
|
||||
// spell-checker:ignore unenroll, word2, word3
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```ini
|
||||
# spell-checker:ignore unenroll, word2, word3
|
||||
```
|
||||
@@ -1,218 +0,0 @@
|
||||
# @file SpellCheck.py
|
||||
#
|
||||
# An edk2-pytool based plugin wrapper for cspell
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
import logging
|
||||
import json
|
||||
import yaml
|
||||
from io import StringIO
|
||||
import os
|
||||
from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin
|
||||
from edk2toollib.utility_functions import RunCmd
|
||||
from edk2toolext.environment.var_dict import VarDict
|
||||
from edk2toollib.gitignore_parser import parse_gitignore_lines
|
||||
from edk2toolext.environment import version_aggregator
|
||||
|
||||
|
||||
class SpellCheck(ICiBuildPlugin):
|
||||
"""
|
||||
A CiBuildPlugin that uses the cspell node module to scan the files
|
||||
from the package being tested for spelling errors. The plugin contains
|
||||
the base cspell.json file then thru the configuration options other settings
|
||||
can be changed or extended.
|
||||
|
||||
Configuration options:
|
||||
"SpellCheck": {
|
||||
"AuditOnly": False, # Don't fail the build if there are errors. Just log them
|
||||
"IgnoreFiles": [], # use gitignore syntax to ignore errors in matching files
|
||||
"ExtendWords": [], # words to extend to the dictionary for this package
|
||||
"IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore
|
||||
"AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
|
||||
}
|
||||
"""
|
||||
|
||||
#
|
||||
# A package can remove any of these using IgnoreStandardPaths
|
||||
#
|
||||
STANDARD_PLUGIN_DEFINED_PATHS = ("*.c", "*.h",
|
||||
"*.nasm", "*.asm", "*.masm", "*.s",
|
||||
"*.asl",
|
||||
"*.dsc", "*.dec", "*.fdf", "*.inf",
|
||||
"*.md", "*.txt"
|
||||
)
|
||||
|
||||
def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
|
||||
""" Provide the testcase name and classname for use in reporting
|
||||
|
||||
Args:
|
||||
packagename: string containing name of package to build
|
||||
environment: The VarDict for the test to run in
|
||||
Returns:
|
||||
a tuple containing the testcase name and the classname
|
||||
(testcasename, classname)
|
||||
testclassname: a descriptive string for the testcase can include whitespace
|
||||
classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>
|
||||
"""
|
||||
return ("Spell check files in " + packagename, packagename + ".SpellCheck")
|
||||
|
||||
##
|
||||
# External function of plugin. This function is used to perform the task of the CiBuild Plugin
|
||||
#
|
||||
# - package is the edk2 path to package. This means workspace/packagepath relative.
|
||||
# - edk2path object configured with workspace and packages path
|
||||
# - PkgConfig Object (dict) for the pkg
|
||||
# - EnvConfig Object
|
||||
# - Plugin Manager Instance
|
||||
# - Plugin Helper Obj Instance
|
||||
# - Junit Logger
|
||||
# - output_stream the StringIO output stream from this plugin via logging
|
||||
|
||||
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
|
||||
Errors = []
|
||||
|
||||
abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(
|
||||
packagename)
|
||||
|
||||
if abs_pkg_path is None:
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("No package {0}".format(packagename))
|
||||
return -1
|
||||
|
||||
# check for node
|
||||
return_buffer = StringIO()
|
||||
ret = RunCmd("node", "--version", outstream=return_buffer)
|
||||
if (ret != 0):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("NodeJs not installed. Test can't run")
|
||||
logging.warning("NodeJs not installed. Test can't run")
|
||||
return -1
|
||||
node_version = return_buffer.getvalue().strip() # format vXX.XX.XX
|
||||
tc.LogStdOut(f"Node version: {node_version}")
|
||||
version_aggregator.GetVersionAggregator().ReportVersion(
|
||||
"NodeJs", node_version, version_aggregator.VersionTypes.INFO)
|
||||
|
||||
# Check for cspell
|
||||
return_buffer = StringIO()
|
||||
ret = RunCmd("cspell", "--version", outstream=return_buffer)
|
||||
if (ret != 0):
|
||||
tc.SetSkipped()
|
||||
tc.LogStdError("cspell not installed. Test can't run")
|
||||
logging.warning("cspell not installed. Test can't run")
|
||||
return -1
|
||||
cspell_version = return_buffer.getvalue().strip() # format XX.XX.XX
|
||||
tc.LogStdOut(f"CSpell version: {cspell_version}")
|
||||
version_aggregator.GetVersionAggregator().ReportVersion(
|
||||
"CSpell", cspell_version, version_aggregator.VersionTypes.INFO)
|
||||
|
||||
# copy the default as a list
|
||||
package_relative_paths_to_spell_check = list(SpellCheck.STANDARD_PLUGIN_DEFINED_PATHS)
|
||||
|
||||
#
|
||||
# Allow the ci.yaml to remove any of the above standard paths
|
||||
#
|
||||
if("IgnoreStandardPaths" in pkgconfig):
|
||||
for a in pkgconfig["IgnoreStandardPaths"]:
|
||||
if(a in package_relative_paths_to_spell_check):
|
||||
tc.LogStdOut(
|
||||
f"ignoring standard path due to ci.yaml ignore: {a}")
|
||||
package_relative_paths_to_spell_check.remove(a)
|
||||
else:
|
||||
tc.LogStdOut(f"Invalid IgnoreStandardPaths value: {a}")
|
||||
|
||||
#
|
||||
# check for any additional include paths defined by package config
|
||||
#
|
||||
if("AdditionalIncludePaths" in pkgconfig):
|
||||
package_relative_paths_to_spell_check.extend(
|
||||
pkgconfig["AdditionalIncludePaths"])
|
||||
|
||||
#
|
||||
# Make the path string for cspell to check
|
||||
#
|
||||
relpath = os.path.relpath(abs_pkg_path)
|
||||
cpsell_paths = " ".join(
|
||||
# Double quote each path to defer expansion to cspell parameters
|
||||
[f'"{relpath}/**/{x}"' for x in package_relative_paths_to_spell_check])
|
||||
|
||||
# Make the config file
|
||||
config_file_path = os.path.join(
|
||||
Edk2pathObj.WorkspacePath, "Build", packagename, "cspell_actual_config.json")
|
||||
mydir = os.path.dirname(os.path.abspath(__file__))
|
||||
# load as yaml so it can have comments
|
||||
base = os.path.join(mydir, "cspell.base.yaml")
|
||||
with open(base, "r") as i:
|
||||
config = yaml.safe_load(i)
|
||||
|
||||
if("ExtendWords" in pkgconfig):
|
||||
config["words"].extend(pkgconfig["ExtendWords"])
|
||||
with open(config_file_path, "w") as o:
|
||||
json.dump(config, o) # output as json so compat with cspell
|
||||
|
||||
All_Ignores = []
|
||||
# Parse the config for other ignores
|
||||
if "IgnoreFiles" in pkgconfig:
|
||||
All_Ignores.extend(pkgconfig["IgnoreFiles"])
|
||||
|
||||
# spell check all the files
|
||||
ignore = parse_gitignore_lines(All_Ignores, os.path.join(
|
||||
abs_pkg_path, "nofile.txt"), abs_pkg_path)
|
||||
|
||||
# result is a list of strings like this
|
||||
# C:\src\sp-edk2\edk2\FmpDevicePkg\FmpDevicePkg.dec:53:9 - Unknown word (Capule)
|
||||
EasyFix = []
|
||||
results = self._check_spelling(cpsell_paths, config_file_path)
|
||||
for r in results:
|
||||
path, _, word = r.partition(" - Unknown word ")
|
||||
if len(word) == 0:
|
||||
# didn't find pattern
|
||||
continue
|
||||
|
||||
pathinfo = path.rsplit(":", 2) # remove the line no info
|
||||
if(ignore(pathinfo[0])): # check against ignore list
|
||||
tc.LogStdOut(f"ignoring error due to ci.yaml ignore: {r}")
|
||||
continue
|
||||
|
||||
# real error
|
||||
EasyFix.append(word.strip().strip("()"))
|
||||
Errors.append(r)
|
||||
|
||||
# Log all errors tc StdError
|
||||
for l in Errors:
|
||||
tc.LogStdError(l.strip())
|
||||
|
||||
# Helper - Log the syntax needed to add these words to dictionary
|
||||
if len(EasyFix) > 0:
|
||||
EasyFix = sorted(set(a.lower() for a in EasyFix))
|
||||
tc.LogStdOut("\n Easy fix:")
|
||||
OneString = "If these are not errors add this to your ci.yaml file.\n"
|
||||
OneString += '"SpellCheck": {\n "ExtendWords": ['
|
||||
for a in EasyFix:
|
||||
tc.LogStdOut(f'\n"{a}",')
|
||||
OneString += f'\n "{a}",'
|
||||
logging.info(OneString.rstrip(",") + '\n ]\n}')
|
||||
|
||||
# add result to test case
|
||||
overall_status = len(Errors)
|
||||
if overall_status != 0:
|
||||
if "AuditOnly" in pkgconfig and pkgconfig["AuditOnly"]:
|
||||
# set as skipped if AuditOnly
|
||||
tc.SetSkipped()
|
||||
return -1
|
||||
else:
|
||||
tc.SetFailed("SpellCheck {0} Failed. Errors {1}".format(
|
||||
packagename, overall_status), "CHECK_FAILED")
|
||||
else:
|
||||
tc.SetSuccess()
|
||||
return overall_status
|
||||
|
||||
def _check_spelling(self, abs_file_to_check: str, abs_config_file_to_use: str) -> []:
|
||||
output = StringIO()
|
||||
ret = RunCmd(
|
||||
"cspell", f"--config {abs_config_file_to_use} {abs_file_to_check}", outstream=output)
|
||||
if ret == 0:
|
||||
return []
|
||||
else:
|
||||
return output.getvalue().strip().splitlines()
|
||||
@@ -1,11 +0,0 @@
|
||||
## @file
|
||||
# CiBuildPlugin used to check spelling
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"scope": "cibuild",
|
||||
"name": "Spell Check Test",
|
||||
"module": "SpellCheck"
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
## @file
|
||||
# CSpell configuration
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
{
|
||||
"version": "0.1",
|
||||
"language": "en",
|
||||
"dictionaries": [
|
||||
"companies ",
|
||||
"softwareTerms",
|
||||
"python",
|
||||
"cpp"
|
||||
],
|
||||
"ignorePaths": [
|
||||
"*.pdb",
|
||||
"**/*_extdep/**",
|
||||
"*.pdf",
|
||||
"*.exe",
|
||||
"*.jpg"
|
||||
],
|
||||
"minWordLength": 5,
|
||||
"allowCompoundWords": false,
|
||||
"maxNumberOfProblems": 200,
|
||||
"maxDuplicateProblems": 200,
|
||||
"ignoreWords": [
|
||||
"muchange"
|
||||
],
|
||||
"words": [
|
||||
"MTRRs",
|
||||
"Microarchitecture",
|
||||
"Goldmont",
|
||||
"cpuid",
|
||||
"mwait",
|
||||
"cstate",
|
||||
"smram",
|
||||
"scrtm",
|
||||
"smbus",
|
||||
"selftest",
|
||||
"socket",
|
||||
"MMRAM",
|
||||
"qword",
|
||||
"ENDBR",
|
||||
"SMBASE",
|
||||
"FXSAVE",
|
||||
"FXRSTOR",
|
||||
"RDRAND",
|
||||
"IOAPIC",
|
||||
"ATAPI",
|
||||
"movsb",
|
||||
"iretw",
|
||||
"XENSTORE",
|
||||
"cdrom",
|
||||
"oprom",
|
||||
"oproms",
|
||||
"varstore",
|
||||
"EKU",
|
||||
"ascii",
|
||||
"nmake",
|
||||
"NVDIMM",
|
||||
"nasmb",
|
||||
"Mtftp",
|
||||
"Hypercall",
|
||||
"hypercalls",
|
||||
"IOMMU",
|
||||
"QEMU",
|
||||
"qemus",
|
||||
"OVMF",
|
||||
"tiano",
|
||||
"tianocore",
|
||||
"edkii",
|
||||
"coreboot",
|
||||
"uefipayload",
|
||||
"bootloader",
|
||||
"bootloaders",
|
||||
"mdepkg",
|
||||
"skuid",
|
||||
"dxefv",
|
||||
"toolchain",
|
||||
"libraryclass",
|
||||
"preboot",
|
||||
"pythonpath",
|
||||
"cygpath",
|
||||
"nuget",
|
||||
"basetools",
|
||||
"prepi",
|
||||
"OPTEE",
|
||||
"stringid",
|
||||
"peims",
|
||||
"memmap",
|
||||
"guids",
|
||||
"uuids",
|
||||
"smbios",
|
||||
"certdb",
|
||||
"certdbv",
|
||||
"EfiSigList",
|
||||
"depex",
|
||||
"IHANDLE",
|
||||
"Virtio",
|
||||
"Mbytes",
|
||||
"Citrix",
|
||||
"initrd",
|
||||
"semihost",
|
||||
"Semihosting",
|
||||
"Trustzone",
|
||||
"Fastboot",
|
||||
"framebuffer",
|
||||
"genfw",
|
||||
"TTYTERM",
|
||||
"miniport",
|
||||
"LFENCE",
|
||||
"PCANSI",
|
||||
"submodule",
|
||||
"submodules",
|
||||
"brotli",
|
||||
"PCCTS",
|
||||
"softfloat",
|
||||
"whitepaper",
|
||||
"ACPICA",
|
||||
"plugfest",
|
||||
"bringup",
|
||||
"formset", #VFR
|
||||
"ideqvallist",
|
||||
"numberof",
|
||||
"oneof",
|
||||
"endformset",
|
||||
"endnumeric",
|
||||
"endoneof",
|
||||
"disableif",
|
||||
"guidid",
|
||||
"classguid",
|
||||
"efivarstore",
|
||||
"formsetguid",
|
||||
"formid",
|
||||
"suppressif",
|
||||
"grayoutif",
|
||||
"ideqval",
|
||||
"endform",
|
||||
"endcheckbox",
|
||||
"questionid",
|
||||
"questionref",
|
||||
"enddate",
|
||||
"endstring",
|
||||
"guidop",
|
||||
"endguidop",
|
||||
"langdef",
|
||||
"dynamicex",
|
||||
"tokenspace",
|
||||
"tokenguid",
|
||||
"pcd's", #seems like cspell bug
|
||||
"peim's",
|
||||
"autogen",
|
||||
"Disasm",
|
||||
"Torito",
|
||||
"SRIOV",
|
||||
"MRIOV",
|
||||
"UARTs",
|
||||
"Consplitter", # common module in UEFI
|
||||
"FIFOs",
|
||||
"ACPINVS",
|
||||
"Endof", # due to of not being uppercase
|
||||
"bootability",
|
||||
"Sdhci",
|
||||
"inmodule",
|
||||
"RISCV",
|
||||
"edksetup",
|
||||
"iscsi",
|
||||
"nvdata",
|
||||
"pytools",
|
||||
"NTDDI",
|
||||
"Wnonportable",
|
||||
"CLANGPDB",
|
||||
"nologo",
|
||||
"lldmap",
|
||||
"ASMLINK",
|
||||
"NODEFAULTLIB",
|
||||
"vcruntimed",
|
||||
"ucrtd",
|
||||
"msvcrtd",
|
||||
"XIPFLAGS"
|
||||
]
|
||||
}
|
||||
@@ -1,294 +0,0 @@
|
||||
# Edk2 Continuous Integration
|
||||
|
||||
## Basic Status
|
||||
|
||||
| Package | Windows VS2019 (IA32/X64)| Ubuntu GCC (IA32/X64/ARM/AARCH64) | Known Issues |
|
||||
| :---- | :----- | :---- | :--- |
|
||||
| ArmPkg | | :heavy_check_mark: |
|
||||
| ArmPlatformPkg | | :heavy_check_mark: |
|
||||
| ArmVirtPkg | SEE PACKAGE README | SEE PACKAGE README |
|
||||
| CryptoPkg | :heavy_check_mark: | :heavy_check_mark: | Spell checking in audit mode
|
||||
| DynamicTablesPkg | | :heavy_check_mark: |
|
||||
| EmbeddedPkg |
|
||||
| EmulatorPkg | SEE PACKAGE README | SEE PACKAGE README | Spell checking in audit mode
|
||||
| FatPkg | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| FmpDevicePkg | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| IntelFsp2Pkg |
|
||||
| IntelFsp2WrapperPkg |
|
||||
| MdeModulePkg | :heavy_check_mark: | :heavy_check_mark: | DxeIpl dependency on ArmPkg, Depends on StandaloneMmPkg, Spell checking in audit mode
|
||||
| MdePkg | :heavy_check_mark: | :heavy_check_mark: | Spell checking in audit mode
|
||||
| NetworkPkg | :heavy_check_mark: | :heavy_check_mark: | Spell checking in audit mode
|
||||
| OvmfPkg | SEE PACKAGE README | SEE PACKAGE README | Spell checking in audit mode
|
||||
| PcAtChipsetPkg | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| SecurityPkg | :heavy_check_mark: | :heavy_check_mark: | Spell checking in audit mode
|
||||
| ShellPkg | :heavy_check_mark: | :heavy_check_mark: | Spell checking in audit mode, 3 modules are not being built by DSC
|
||||
| SignedCapsulePkg |
|
||||
| SourceLevelDebugPkg |
|
||||
| StandaloneMmPkg | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| UefiCpuPkg | :heavy_check_mark: | :heavy_check_mark: | Spell checking in audit mode, 2 binary modules not being built by DSC
|
||||
| UefiPayloadPkg |
|
||||
| UnitTestFrameworkPkg | :heavy_check_mark: | :heavy_check_mark: |
|
||||
|
||||
For more detailed status look at the test results of the latest CI run on the
|
||||
repo readme.
|
||||
|
||||
## Background
|
||||
|
||||
This Continuous integration and testing infrastructure leverages the TianoCore EDKII Tools PIP modules:
|
||||
[library](https://pypi.org/project/edk2-pytool-library/) and
|
||||
[extensions](https://pypi.org/project/edk2-pytool-extensions/) (with repos
|
||||
located [here](https://github.com/tianocore/edk2-pytool-library) and
|
||||
[here](https://github.com/tianocore/edk2-pytool-extensions)).
|
||||
|
||||
The primary execution flows can be found in the
|
||||
`.azurepipelines/Windows-VS2019.yml` and `.azurepipelines/Ubuntu-GCC5.yml`
|
||||
files. These YAML files are consumed by the Azure Dev Ops Build Pipeline and
|
||||
dictate what server resources should be used, how they should be configured, and
|
||||
what processes should be run on them. An overview of this schema can be found
|
||||
[here](https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema).
|
||||
|
||||
Inspection of these files reveals the EDKII Tools commands that make up the
|
||||
primary processes for the CI build: 'stuart_setup', 'stuart_update', and
|
||||
'stuart_ci_build'. These commands come from the EDKII Tools PIP modules and are
|
||||
configured as described below. More documentation on the tools can be
|
||||
found [here](https://github.com/tianocore/edk2-pytool-extensions/blob/master/docs/using.md)
|
||||
and [here](https://github.com/tianocore/edk2-pytool-extensions/blob/master/docs/features/feature_invocables.md).
|
||||
|
||||
## Configuration
|
||||
|
||||
Configuration of the CI process consists of (in order of precedence):
|
||||
|
||||
* command-line arguments passed in via the Pipeline YAML
|
||||
* a per-package configuration file (e.g. `<package-name>.ci.yaml`) that is
|
||||
detected by the CI system in EDKII Tools.
|
||||
* a global configuration Python module (e.g. `CISetting.py`) passed in via the
|
||||
command-line
|
||||
|
||||
The global configuration file is described in
|
||||
[this readme](https://github.com/tianocore/edk2-pytool-extensions/blob/master/docs/usability/using_settings_manager.md)
|
||||
from the EDKII Tools documentation. This configuration is written as a Python
|
||||
module so that decisions can be made dynamically based on command line
|
||||
parameters and codebase state.
|
||||
|
||||
The per-package configuration file can override most settings in the global
|
||||
configuration file, but is not dynamic. This file can be used to skip or
|
||||
customize tests that may be incompatible with a specific package. Each test generally requires
|
||||
per package configuration which comes from this file.
|
||||
|
||||
## Running CI locally
|
||||
|
||||
The EDKII Tools environment (and by extension the ci) is designed to support
|
||||
easily and consistently running locally and in a cloud ci environment. To do
|
||||
that a few steps should be followed. Details of EDKII Tools can be found in the
|
||||
[docs folder here](https://github.com/tianocore/edk2-pytool-extensions/tree/master/docs)
|
||||
|
||||
### Prerequisets
|
||||
|
||||
1. A supported toolchain (others might work but this is what is tested and validated)
|
||||
* Windows 10:
|
||||
* VS 2017 or VS 2019
|
||||
* Windows SDK (for rc)
|
||||
* Windows WDK (for capsules)
|
||||
* Ubuntu 18.04 or Fedora
|
||||
* GCC5
|
||||
* Easy to add more but this is the current state
|
||||
2. Python 3.7.x or newer on path
|
||||
3. git on path
|
||||
4. Recommended to setup and activate a python virtual environment
|
||||
5. Install the requirements `pip install --upgrade pip-requirements.txt`
|
||||
|
||||
### Running CI
|
||||
|
||||
1. clone your edk2 repo
|
||||
2. Activate your python virtual environment in cmd window
|
||||
3. Get code dependencies (done only when submodules change)
|
||||
* `stuart_setup -c .pytool/CISettings.py TOOL_CHAIN_TAG=<your tag here>`
|
||||
4. Update other dependencies (done more often)
|
||||
* `stuart_update -c .pytool/CISettings.py TOOL_CHAIN_TAG=<your tag here>`
|
||||
5. Run CI build (--help will give you options)
|
||||
* `stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=<your tag here>`
|
||||
* -p <pkg1,pkg2,pkg3> : To build only certain packages use a CSV list
|
||||
* -a <arch1,arch2,arch3>: To run only certain architectures use a CSV list
|
||||
* -t <target1,target2>: To run only tests related to certain targets use a
|
||||
CSV list
|
||||
* By default all tests are opted in. Then given a package.ci.yaml file those
|
||||
tests can be configured for a package. Finally setting the check to the
|
||||
value `skip` will skip that plugin. Examples:
|
||||
* `CompilerPlugin=skip` skip the build test
|
||||
* `GuidCheck=skip` skip the Guid check
|
||||
* `SpellCheck=skip` skip the spell checker
|
||||
* etc
|
||||
6. Detailed reports and logs per package are captured in the `Build` directory
|
||||
|
||||
## Current PyTool Test Capabilities
|
||||
|
||||
All CI tests are instances of EDKII Tools plugins. Documentation on the plugin
|
||||
system can be found [here](https://github.com/tianocore/edk2-pytool-extensions/blob/master/docs/usability/using_plugin_manager.md)
|
||||
and [here](https://github.com/tianocore/edk2-pytool-extensions/blob/master/docs/features/feature_plugin_manager.md).
|
||||
Upon invocation, each plugin will be passed the path to the current package
|
||||
under test and a dictionary containing its targeted configuration, as assembled
|
||||
from the command line, per-package configuration, and global configuration.
|
||||
|
||||
Note: CI plugins are considered unique from build plugins and helper plugins,
|
||||
even though some CI plugins may execute steps of a build.
|
||||
|
||||
In the example, these plugins live alongside the code under test (in the
|
||||
`.pytool/Plugin` directory), but may be moved to the 'edk2-test' repo if that
|
||||
location makes more sense for the community.
|
||||
|
||||
### Module Inclusion Test - DscCompleteCheck
|
||||
|
||||
This scans all INF files from a package and confirms they are
|
||||
listed in the package level DSC file. The test considers it an error if any INF
|
||||
does not appear in the `Components` section of the package-level DSC (indicating
|
||||
that it would not be built if the package were built). This is critical because
|
||||
much of the CI infrastructure assumes that all modules will be listed in the DSC
|
||||
and compiled.
|
||||
|
||||
This test will ignore INFs in the following cases:
|
||||
|
||||
1. When `MODULE_TYPE` = `HOST_APPLICATION`
|
||||
2. When a Library instance **only** supports the `HOST_APPLICATION` environment
|
||||
|
||||
### Host Module Inclusion Test - HostUnitTestDscCompleteCheck
|
||||
|
||||
This test scans all INF files from a package for those related to host
|
||||
based unit tests and confirms they are listed in the unit test DSC file for the package.
|
||||
The test considers it an error if any INF meeting the requirements does not appear
|
||||
in the `Components` section of the unit test DSC. This is critical because
|
||||
much of the CI infrastructure assumes that modules will be listed in the DSC
|
||||
and compiled.
|
||||
|
||||
This test will only require INFs in the following cases:
|
||||
|
||||
1. When `MODULE_TYPE` = `HOST_APPLICATION`
|
||||
2. When a Library instance explicitly supports the `HOST_APPLICATION` environment
|
||||
|
||||
### Code Compilation Test - CompilerPlugin
|
||||
|
||||
Once the Module Inclusion Test has verified that all modules would be built if
|
||||
all package-level DSCs were built, the Code Compilation Test simply runs through
|
||||
and builds every package-level DSC on every toolchain and for every architecture
|
||||
that is supported. Any module that fails to build is considered an error.
|
||||
|
||||
### Host Unit Test Compilation and Run Test - HostUnitTestCompilerPlugin
|
||||
|
||||
A test that compiles the dsc for host based unit test apps.
|
||||
On Windows this will also enable a build plugin to execute that will run the unit tests and verify the results.
|
||||
|
||||
These tools will be invoked on any CI
|
||||
pass that includes the NOOPT target. In order for these tools to do their job,
|
||||
the package and tests must be configured in a particular way...
|
||||
|
||||
#### Including Host-Based Tests in the Package YAML
|
||||
|
||||
For example, looking at the `MdeModulePkg.ci.yaml` config file, there are two
|
||||
config options that control HostBased test behavior:
|
||||
|
||||
```json
|
||||
## options defined .pytool/Plugin/HostUnitTestCompilerPlugin
|
||||
"HostUnitTestCompilerPlugin": {
|
||||
"DscPath": "Test/MdeModulePkgHostTest.dsc"
|
||||
},
|
||||
```
|
||||
|
||||
This option tell the test builder to run. The test builder needs to know which
|
||||
modules in this package are host-based tests, so that DSC path is provided.
|
||||
|
||||
#### Configuring the HostBased DSC
|
||||
|
||||
The HostBased DSC for `MdeModulePkg` is located at
|
||||
`MdeModulePkg/Test/MdeModulePkgHostTest.dsc`.
|
||||
|
||||
To add automated host-based unit test building to a new package, create a
|
||||
similar DSC. The new DSC should make sure to have the `NOOPT` BUILD_TARGET
|
||||
and should include the line:
|
||||
|
||||
```
|
||||
!include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
|
||||
```
|
||||
|
||||
All of the modules that are included in the `Components` section of this
|
||||
DSC should be of type HOST_APPLICATION.
|
||||
|
||||
### GUID Uniqueness Test - GuidCheck
|
||||
|
||||
This test works on the collection of all packages rather than an individual
|
||||
package. It looks at all FILE_GUIDs and GUIDs declared in DEC files and ensures
|
||||
that they are unique for the codebase. This prevents, for example, accidental
|
||||
duplication of GUIDs when using an existing INF as a template for a new module.
|
||||
|
||||
### Cross-Package Dependency Test - DependencyCheck
|
||||
|
||||
This test compares the list of all packages used in INFs files for a given
|
||||
package against a list of "allowed dependencies" in plugin configuration for
|
||||
that package. Any module that depends on a disallowed package will cause a test
|
||||
failure.
|
||||
|
||||
### Library Declaration Test - LibraryClassCheck
|
||||
|
||||
This test scans at all library header files found in the `Library` folders in
|
||||
all of the package's declared include directories and ensures that all files
|
||||
have a matching LibraryClass declaration in the DEC file for the package. Any
|
||||
missing declarations will cause a failure.
|
||||
|
||||
### Invalid Character Test - CharEncodingCheck
|
||||
|
||||
This test scans all files in a package to make sure that there are no invalid
|
||||
Unicode characters that may cause build errors in some character
|
||||
sets/localizations.
|
||||
|
||||
### Spell Checking - cspell
|
||||
|
||||
This test runs a spell checker on all files within the package. This is done
|
||||
using the NodeJs cspell tool. For details check `.pytool/Plugin/SpellCheck`.
|
||||
For this plugin to run during ci you must install nodejs and cspell and have
|
||||
both available to the command line when running your CI.
|
||||
|
||||
Install
|
||||
|
||||
* Install nodejs from https://nodejs.org/en/
|
||||
* Install cspell
|
||||
1. Open cmd prompt with access to node and npm
|
||||
2. Run `npm install -g cspell`
|
||||
|
||||
More cspell info: https://github.com/streetsidesoftware/cspell
|
||||
|
||||
### License Checking - LicenseCheck
|
||||
|
||||
Scans all new added files in a package to make sure code is contributed under
|
||||
BSD-2-Clause-Patent.
|
||||
|
||||
### Ecc tool - EccCheck
|
||||
|
||||
Run the Ecc tool on the package. The Ecc tool is available in the BaseTools
|
||||
package. It checks that the code complies to the EDKII coding standard.
|
||||
|
||||
## PyTool Scopes
|
||||
|
||||
Scopes are how the PyTool ext_dep, path_env, and plugins are activated. Meaning
|
||||
that if an invocable process has a scope active then those ext_dep and path_env
|
||||
will be active. To allow easy integration of PyTools capabilities there are a
|
||||
few standard scopes.
|
||||
|
||||
| Scope | Invocable | Description |
|
||||
| :---- | :----- | :---- |
|
||||
| global | edk2_invocable++ - should be base_abstract_invocable | Running an invocables |
|
||||
| global-win | edk2_invocable++ | Running on Microsoft Windows |
|
||||
| global-nix | edk2_invocable++ | Running on Linux based OS |
|
||||
| edk2-build | | This indicates that an invocable is building EDK2 based UEFI code |
|
||||
| cibuild | set in .pytool/CISettings.py | Suggested target for edk2 continuous integration builds. Tools used for CiBuilds can use this scope. Example: asl compiler |
|
||||
| host-based-test | set in .pytool/CISettings.py | Turns on the host based tests and plugin |
|
||||
| host-test-win | set in .pytool/CISettings.py | Enables the host based test runner for Windows |
|
||||
|
||||
## Future investments
|
||||
|
||||
* PatchCheck tests as plugins
|
||||
* MacOS/xcode support
|
||||
* Clang/LLVM support
|
||||
* Visual Studio AARCH64 and ARM support
|
||||
* BaseTools C tools CI/PR and binary release process
|
||||
* BaseTools Python tools CI/PR process
|
||||
* Extensible private/closed source platform reporting
|
||||
* UEFI SCTs
|
||||
* Other automation
|
||||
36
AppPkg/AppPkg.dec
Normal file
36
AppPkg/AppPkg.dec
Normal file
@@ -0,0 +1,36 @@
|
||||
## @file
|
||||
# Declarations for the UDK Standard Libraries.
|
||||
#
|
||||
# Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials are licensed and made available under
|
||||
# the terms and conditions of the BSD License which accompanies this distribution.
|
||||
# The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
##
|
||||
|
||||
|
||||
[Defines]
|
||||
DEC_SPECIFICATION = 0x00010005
|
||||
PACKAGE_NAME = AppPkg
|
||||
PACKAGE_GUID = B3E3D3D5-D62B-4497-A175-264F489D127E
|
||||
PACKAGE_VERSION = 0.01
|
||||
|
||||
|
||||
[Guids]
|
||||
gAppPkgTokenSpaceGuid = { 0xe7e1efa6, 0x7607, 0x4a78, { 0xa7, 0xdd, 0x43, 0xe4, 0xbd, 0x72, 0xc0, 0x99 }}
|
||||
|
||||
|
||||
[PcdsFixedAtBuild]
|
||||
gAppPkgTokenSpaceGuid.DataSource_Port|1234|UINT16|0
|
||||
gAppPkgTokenSpaceGuid.Tftp_AckLogBase|4|UINT32|1
|
||||
gAppPkgTokenSpaceGuid.Tftp_AckMultiplier|4|UINT32|2
|
||||
gAppPkgTokenSpaceGuid.Tftp_Bandwidth|0|BOOLEAN|3
|
||||
gAppPkgTokenSpaceGuid.Tftp_HighSpeed|0|BOOLEAN|4
|
||||
gAppPkgTokenSpaceGuid.Tftp_MaxRetry|10|UINT32|5
|
||||
gAppPkgTokenSpaceGuid.Tftp_MaxTimeoutInSec|3|UINT32|6
|
||||
gAppPkgTokenSpaceGuid.WebServer_HttpPort|80|UINT16|7
|
||||
|
||||
152
AppPkg/AppPkg.dsc
Normal file
152
AppPkg/AppPkg.dsc
Normal file
@@ -0,0 +1,152 @@
|
||||
## @file
|
||||
# Intel(r) UEFI Application Development Kit for EDK II.
|
||||
# This package contains applications which depend upon Standard Libraries
|
||||
# from the StdLib package.
|
||||
#
|
||||
# See the comments in the [LibraryClasses.IA32] and [BuildOptions] sections
|
||||
# for important information about configuring this package for your
|
||||
# environment.
|
||||
#
|
||||
# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
##
|
||||
|
||||
[Defines]
|
||||
PLATFORM_NAME = AppPkg
|
||||
PLATFORM_GUID = 0458dade-8b6e-4e45-b773-1b27cbda3e06
|
||||
PLATFORM_VERSION = 0.01
|
||||
DSC_SPECIFICATION = 0x00010006
|
||||
OUTPUT_DIRECTORY = Build/AppPkg
|
||||
SUPPORTED_ARCHITECTURES = IA32|X64|ARM|AARCH64
|
||||
BUILD_TARGETS = DEBUG|RELEASE|NOOPT
|
||||
SKUID_IDENTIFIER = DEFAULT
|
||||
|
||||
#
|
||||
# Debug output control
|
||||
#
|
||||
DEFINE DEBUG_ENABLE_OUTPUT = FALSE # Set to TRUE to enable debug output
|
||||
DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x80000040 # Flags to control amount of debug output
|
||||
DEFINE DEBUG_PROPERTY_MASK = 0
|
||||
|
||||
[PcdsFeatureFlag]
|
||||
|
||||
[PcdsFixedAtBuild]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK)
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL)
|
||||
|
||||
[PcdsFixedAtBuild.IPF]
|
||||
|
||||
[LibraryClasses]
|
||||
#
|
||||
# Entry Point Libraries
|
||||
#
|
||||
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
|
||||
ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
|
||||
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
|
||||
#
|
||||
# Common Libraries
|
||||
#
|
||||
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
|
||||
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
|
||||
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
|
||||
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
|
||||
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
|
||||
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
|
||||
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
|
||||
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
|
||||
!if $(DEBUG_ENABLE_OUTPUT)
|
||||
DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
|
||||
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
|
||||
!else ## DEBUG_ENABLE_OUTPUT
|
||||
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
|
||||
!endif ## DEBUG_ENABLE_OUTPUT
|
||||
|
||||
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
|
||||
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
|
||||
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
|
||||
PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
|
||||
PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
|
||||
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
|
||||
UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
|
||||
HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
|
||||
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
|
||||
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
|
||||
SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
|
||||
|
||||
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
|
||||
|
||||
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
|
||||
|
||||
###################################################################################################
|
||||
#
|
||||
# Components Section - list of the modules and components that will be processed by compilation
|
||||
# tools and the EDK II tools to generate PE32/PE32+/Coff image files.
|
||||
#
|
||||
# Note: The EDK II DSC file is not used to specify how compiled binary images get placed
|
||||
# into firmware volume images. This section is just a list of modules to compile from
|
||||
# source into UEFI-compliant binaries.
|
||||
# It is the FDF file that contains information on combining binary files into firmware
|
||||
# volume images, whose concept is beyond UEFI and is described in PI specification.
|
||||
# Binary modules do not need to be listed in this section, as they should be
|
||||
# specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),
|
||||
# Logo (Logo.bmp), and etc.
|
||||
# There may also be modules listed in this section that are not required in the FDF file,
|
||||
# When a module listed here is excluded from FDF file, then UEFI-compliant binary will be
|
||||
# generated for it, but the binary will not be put into any firmware volume.
|
||||
#
|
||||
###################################################################################################
|
||||
|
||||
[Components]
|
||||
|
||||
#### Sample Applications.
|
||||
AppPkg/Applications/Hello/Hello.inf # No LibC includes or functions.
|
||||
AppPkg/Applications/Main/Main.inf # Simple invocation. No other LibC functions.
|
||||
AppPkg/Applications/Enquire/Enquire.inf #
|
||||
AppPkg/Applications/ArithChk/ArithChk.inf #
|
||||
|
||||
#### A simple fuzzer for OrderedCollectionLib, in particular for
|
||||
#### BaseOrderedCollectionRedBlackTreeLib.
|
||||
AppPkg/Applications/OrderedCollectionTest/OrderedCollectionTest.inf {
|
||||
<LibraryClasses>
|
||||
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
|
||||
DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
|
||||
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
|
||||
<PcdsFeatureFlag>
|
||||
gEfiMdePkgTokenSpaceGuid.PcdValidateOrderedCollection|TRUE
|
||||
<PcdsFixedAtBuild>
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80400040
|
||||
}
|
||||
|
||||
#### Un-comment the following line to build Python 2.7.2.
|
||||
# AppPkg/Applications/Python/PythonCore.inf
|
||||
|
||||
#### Un-comment the following line to build Python 2.7.10.
|
||||
# AppPkg/Applications/Python/Python-2.7.10/Python2710.inf
|
||||
|
||||
#### Un-comment the following line to build Lua.
|
||||
# AppPkg/Applications/Lua/Lua.inf
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Specify whether we are running in an emulation environment, or not.
|
||||
# Define EMULATE if we are, else keep the DEFINE commented out.
|
||||
#
|
||||
# DEFINE EMULATE = 1
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Include Boilerplate text required for building with the Standard Libraries.
|
||||
#
|
||||
##############################################################################
|
||||
!include StdLib/StdLib.inc
|
||||
!include AppPkg/Applications/Sockets/Sockets.inc
|
||||
41
AppPkg/Applications/ArithChk/ArithChk.inf
Normal file
41
AppPkg/Applications/ArithChk/ArithChk.inf
Normal file
@@ -0,0 +1,41 @@
|
||||
## @file
|
||||
# Program to generate an arith.h for use with the gdtoa binary to decimal and decimal to binary
|
||||
# conversion library.
|
||||
#
|
||||
# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = ArithChk
|
||||
FILE_GUID = B6C0DCB6-434E-4BEC-BDAC-8EE7ED8A4EC8
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 0.1
|
||||
ENTRY_POINT = ShellCEntryLib
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
arithchk.c
|
||||
|
||||
[Packages]
|
||||
StdLib/StdLib.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
UefiLib
|
||||
LibC
|
||||
LibStdio
|
||||
LibGdtoa
|
||||
|
||||
[BuildOptions]
|
||||
GCC:*_*_*_CC_FLAGS = -Wno-format-security
|
||||
197
AppPkg/Applications/ArithChk/arithchk.c
Normal file
197
AppPkg/Applications/ArithChk/arithchk.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/** @file
|
||||
Program to generate an arith.h for use with the gdtoa binary to decimal and decimal to binary
|
||||
conversion library.
|
||||
|
||||
Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Copyright (C) 1997, 1998 Lucent Technologies
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of Lucent or any of its entities
|
||||
not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
|
||||
NetBSD: arithchk.c,v 1.2 2006/01/25 15:27:42 kleink Exp
|
||||
****************************************************************/
|
||||
#include <sys/EfiCdefs.h>
|
||||
|
||||
/* Try to deduce arith.h from arithmetic properties. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static int dalign;
|
||||
|
||||
typedef struct Akind {
|
||||
char *name;
|
||||
int kind;
|
||||
} Akind;
|
||||
|
||||
static Akind IEEE_LITTLE_ENDIAN = { "IEEE_LITTLE_ENDIAN", 1 };
|
||||
static Akind IEEE_BIG_ENDIAN = { "IEEE_BIG_ENDIAN", 2 };
|
||||
static Akind IBM = { "IBM", 3 };
|
||||
static Akind VAX = { "VAX", 4 };
|
||||
static Akind CRAY = { "CRAY", 5};
|
||||
|
||||
static Akind *
|
||||
Lcheck()
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
long L[2];
|
||||
} u;
|
||||
struct {
|
||||
double d;
|
||||
long L;
|
||||
} x[2];
|
||||
|
||||
if (sizeof(x) > 2*(sizeof(double) + sizeof(long)))
|
||||
dalign = 1;
|
||||
u.L[0] = u.L[1] = 0;
|
||||
u.d = 1e13;
|
||||
if (u.L[0] == 1117925532 && u.L[1] == -448790528)
|
||||
return &IEEE_BIG_ENDIAN;
|
||||
if (u.L[1] == 1117925532 && u.L[0] == -448790528)
|
||||
return &IEEE_LITTLE_ENDIAN;
|
||||
if (u.L[0] == -2065213935 && u.L[1] == 10752)
|
||||
return &VAX;
|
||||
if (u.L[0] == 1267827943 && u.L[1] == 704643072)
|
||||
return &IBM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Akind *
|
||||
icheck()
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
int L[2];
|
||||
} u;
|
||||
struct {
|
||||
double d;
|
||||
int L;
|
||||
} x[2];
|
||||
|
||||
if (sizeof(x) > 2*(sizeof(double) + sizeof(int)))
|
||||
dalign = 1;
|
||||
u.L[0] = u.L[1] = 0;
|
||||
u.d = 1e13;
|
||||
if (u.L[0] == 1117925532 && u.L[1] == -448790528)
|
||||
return &IEEE_BIG_ENDIAN;
|
||||
if (u.L[1] == 1117925532 && u.L[0] == -448790528)
|
||||
return &IEEE_LITTLE_ENDIAN;
|
||||
if (u.L[0] == -2065213935 && u.L[1] == 10752)
|
||||
return &VAX;
|
||||
if (u.L[0] == 1267827943 && u.L[1] == 704643072)
|
||||
return &IBM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *emptyfmt = ""; /* avoid possible warning message with printf("") */
|
||||
|
||||
static Akind *
|
||||
ccheck()
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
long L;
|
||||
} u;
|
||||
long Cray1;
|
||||
|
||||
/* Cray1 = 4617762693716115456 -- without overflow on non-Crays */
|
||||
Cray1 = printf(emptyfmt) < 0 ? 0 : 4617762;
|
||||
if (printf(emptyfmt, Cray1) >= 0)
|
||||
Cray1 = 1000000*Cray1 + 693716;
|
||||
if (printf(emptyfmt, Cray1) >= 0)
|
||||
Cray1 = 1000000*Cray1 + 115456;
|
||||
u.d = 1e13;
|
||||
if (u.L == Cray1)
|
||||
return &CRAY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
fzcheck()
|
||||
{
|
||||
double a, b;
|
||||
int i;
|
||||
|
||||
a = 1.;
|
||||
b = .1;
|
||||
for(i = 155;; b *= b, i >>= 1) {
|
||||
if (i & 1) {
|
||||
a *= b;
|
||||
if (i == 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
b = a * a;
|
||||
return b == 0.;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
Akind *a = 0;
|
||||
int Ldef = 0;
|
||||
FILE *f;
|
||||
|
||||
#ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */
|
||||
f = fopen("arith.h", "w");
|
||||
if (!f) {
|
||||
printf("Cannot open arith.h\n");
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
f = stdout;
|
||||
#endif
|
||||
|
||||
if (sizeof(double) == 2*sizeof(long))
|
||||
a = Lcheck();
|
||||
else if (sizeof(double) == 2*sizeof(int)) {
|
||||
Ldef = 1;
|
||||
a = icheck();
|
||||
}
|
||||
else if (sizeof(double) == sizeof(long))
|
||||
a = ccheck();
|
||||
if (a) {
|
||||
fprintf(f, "#define %s\n#define Arith_Kind_ASL %d\n",
|
||||
a->name, a->kind);
|
||||
if (Ldef)
|
||||
fprintf(f, "#define Long int\n#define Intcast (int)(long)\n");
|
||||
if (dalign)
|
||||
fprintf(f, "#define Double_Align\n");
|
||||
if (sizeof(char*) == 8)
|
||||
fprintf(f, "#define X64_bit_pointers\n");
|
||||
#ifndef NO_LONG_LONG
|
||||
if (sizeof(long long) < 8)
|
||||
#endif
|
||||
fprintf(f, "#define NO_LONG_LONG\n");
|
||||
if (a->kind <= 2 && fzcheck())
|
||||
fprintf(f, "#define Sudden_Underflow\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(f, "/* Unknown arithmetic */\n");
|
||||
return 1;
|
||||
}
|
||||
3377
AppPkg/Applications/Enquire/Enquire.c
Normal file
3377
AppPkg/Applications/Enquire/Enquire.c
Normal file
File diff suppressed because it is too large
Load Diff
53
AppPkg/Applications/Enquire/Enquire.inf
Normal file
53
AppPkg/Applications/Enquire/Enquire.inf
Normal file
@@ -0,0 +1,53 @@
|
||||
## @file
|
||||
# Enquire application for system integer and floating point characteristics
|
||||
# enquiry.
|
||||
#
|
||||
# Due to the level of hardware introspection, this application MUST be built
|
||||
# with optimizations disabled.
|
||||
#
|
||||
# COPYRIGHT(c) 1993-9 Steven Pemberton, CWI. All rights reserved.
|
||||
# NOTE: Improvements gratefully received. Please mention the version.
|
||||
# "http://www.cwi.nl/~steven/enquire.html"
|
||||
#
|
||||
# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = Enquire
|
||||
FILE_GUID = 42f58b27-5dc3-4fa7-844d-5a7dbff06432
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 0.1
|
||||
ENTRY_POINT = ShellCEntryLib
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF
|
||||
#
|
||||
|
||||
[Sources]
|
||||
Enquire.c
|
||||
|
||||
[Packages]
|
||||
StdLib/StdLib.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
UefiLib
|
||||
LibC
|
||||
LibString
|
||||
LibStdio
|
||||
LibGdtoa
|
||||
LibWchar
|
||||
|
||||
[BuildOptions]
|
||||
INTEL:*_*_*_CC_FLAGS = /Qdiag-disable:181,186
|
||||
MSFT:*_*_*_CC_FLAGS = /Od
|
||||
GCC:*_*_*_CC_FLAGS = -O0 -Wno-unused-variable
|
||||
37
AppPkg/Applications/Hello/Hello.c
Normal file
37
AppPkg/Applications/Hello/Hello.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/** @file
|
||||
A simple, basic, EDK II native, "hello" application to verify that
|
||||
we can build applications without LibC.
|
||||
|
||||
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
**/
|
||||
#include <Uefi.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/ShellCEntryLib.h>
|
||||
|
||||
/***
|
||||
Print a welcoming message.
|
||||
|
||||
Establishes the main structure of the application.
|
||||
|
||||
@retval 0 The application exited normally.
|
||||
@retval Other An error occurred.
|
||||
***/
|
||||
INTN
|
||||
EFIAPI
|
||||
ShellAppMain (
|
||||
IN UINTN Argc,
|
||||
IN CHAR16 **Argv
|
||||
)
|
||||
{
|
||||
Print(L"Hello there fellow Programmer.\n");
|
||||
Print(L"Welcome to the world of EDK II.\n");
|
||||
|
||||
return(0);
|
||||
}
|
||||
36
AppPkg/Applications/Hello/Hello.inf
Normal file
36
AppPkg/Applications/Hello/Hello.inf
Normal file
@@ -0,0 +1,36 @@
|
||||
## @file
|
||||
# A simple, basic, EDK II native, "hello" application.
|
||||
#
|
||||
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = Hello
|
||||
FILE_GUID = a912f198-7f0e-4803-b908-b757b806ec83
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 0.1
|
||||
ENTRY_POINT = ShellCEntryLib
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF
|
||||
#
|
||||
|
||||
[Sources]
|
||||
Hello.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
UefiLib
|
||||
ShellCEntryLib
|
||||
69
AppPkg/Applications/Lua/Copyright.txt
Normal file
69
AppPkg/Applications/Lua/Copyright.txt
Normal file
@@ -0,0 +1,69 @@
|
||||
Lua is designed, implemented, and maintained by a team at PUC-Rio, the
|
||||
Pontifical Catholic University of Rio de Janeiro in Brazil. Lua was born and
|
||||
raised in Tecgraf, formerly the Computer Graphics Technology Group of PUC-Rio.
|
||||
Lua is now housed at LabLua, a laboratory of the Department of Computer Science
|
||||
of PUC-Rio.
|
||||
|
||||
The initial work to provide the UEFI implementation of Lua was done at
|
||||
Emulex Corporation.
|
||||
|
||||
Some final packaging and build file "beautification" was done at
|
||||
Intel Corporation.
|
||||
|
||||
Copyright notices, applying to this package and its contents, follow below.
|
||||
These notices will be updated as necessitated by ongoing maintenance and
|
||||
enhancement.
|
||||
|
||||
--------
|
||||
Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials are licensed and made available under
|
||||
the terms and conditions of the BSD License that accompanies this distribution.
|
||||
The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
--------
|
||||
Copyright (c) 2014, Emulex Corporation 3333 Susan Street, Costa Mesa, CA 92626
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
--------
|
||||
Copyright (C) 1994-2013 Lua.org, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
54
AppPkg/Applications/Lua/Lua.inf
Normal file
54
AppPkg/Applications/Lua/Lua.inf
Normal file
@@ -0,0 +1,54 @@
|
||||
## @file
|
||||
# Lua.inf
|
||||
#
|
||||
# UEFI port of the Lua scripting language, Lua 5.2.3, released on 11 Nov 2013
|
||||
#
|
||||
# Copyright (c) 2014, Emulex Corporation 3333 Susan Street, Costa Mesa, CA 92626
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = Lua
|
||||
FILE_GUID = d6a9a1b9-4bfd-d61e-f037-3fa4ca06e046
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 0.1
|
||||
ENTRY_POINT = ShellCEntryLib
|
||||
|
||||
[Sources]
|
||||
./src/lua.c
|
||||
|
||||
[Packages]
|
||||
StdLib/StdLib.dec
|
||||
MdePkg/MdePkg.dec
|
||||
ShellPkg/ShellPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
LibC
|
||||
LibStdio
|
||||
LibStdLib
|
||||
LibSignal
|
||||
LibString
|
||||
LibMath
|
||||
LibTime
|
||||
DevShell
|
||||
UefiLib
|
||||
ShellCEntryLib
|
||||
LuaLib
|
||||
72
AppPkg/Applications/Lua/LuaLib.inf
Normal file
72
AppPkg/Applications/Lua/LuaLib.inf
Normal file
@@ -0,0 +1,72 @@
|
||||
## @file
|
||||
# LuaLib.inf
|
||||
#
|
||||
# Copyright (c) 2014, Emulex Corporation 3333 Susan Street, Costa Mesa, CA 92626
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010006
|
||||
BASE_NAME = LuaLib
|
||||
FILE_GUID = 4e38555c-4f92-20c5-a563-fe907585662d
|
||||
MODULE_TYPE = UEFI_APPLICATION
|
||||
VERSION_STRING = 0.1
|
||||
LIBRARY_CLASS = LuaLib
|
||||
|
||||
[Sources]
|
||||
src/lapi.c
|
||||
src/lauxlib.c
|
||||
src/lbaselib.c
|
||||
src/lbitlib.c
|
||||
src/lcode.c
|
||||
src/lcorolib.c
|
||||
src/lctype.c
|
||||
src/ldblib.c
|
||||
src/ldebug.c
|
||||
src/ldo.c
|
||||
src/ldump.c
|
||||
src/lfunc.c
|
||||
src/lgc.c
|
||||
src/linit.c
|
||||
src/liolib.c
|
||||
src/llex.c
|
||||
src/lmathlib.c
|
||||
src/lmem.c
|
||||
src/loadlib.c
|
||||
src/lobject.c
|
||||
src/lopcodes.c
|
||||
src/loslib.c
|
||||
src/lparser.c
|
||||
src/lstate.c
|
||||
src/lstring.c
|
||||
src/lstrlib.c
|
||||
src/ltable.c
|
||||
src/ltablib.c
|
||||
src/ltm.c
|
||||
src/lundump.c
|
||||
src/lvm.c
|
||||
src/lzio.c
|
||||
|
||||
[Packages]
|
||||
StdLib/StdLib.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[BuildOptions]
|
||||
MSFT:*_*_*_CC_FLAGS = /Oi- /wd4702
|
||||
35
AppPkg/Applications/Lua/ReadMe.txt
Normal file
35
AppPkg/Applications/Lua/ReadMe.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
This is Lua 5.2.3, released on 11 Nov 2013.
|
||||
|
||||
For installation instructions, license details, and
|
||||
further information about Lua, see doc/readme.html.
|
||||
=================================================
|
||||
|
||||
Embedding Lua
|
||||
-------------
|
||||
The Lua library instance, LuaLib, is defined by StdLib.inc. Since, currently, all applications which
|
||||
embed Lua are also StdLib applications, StdLib.inc will be included by your package's .DSC file.
|
||||
|
||||
The header files required to use LuaLib are in the standard include path at StdLib\Include\Lua.
|
||||
They may be referenced as:
|
||||
#include <Lua/lua.h>
|
||||
#include <Lua/lualib.h>
|
||||
#include <Lua/lauxlib>
|
||||
#include <Lua/luaconf.h>
|
||||
|
||||
Lua/luaconf.h is the Lua configuration file. If you wish to build Lua with custom characteristics,
|
||||
this is the file to modify. Modify the file in StdLib\Include\Lua since the file in the Lua
|
||||
source tree is just a stub which references the file in StdLib.
|
||||
|
||||
|
||||
Installation on UEFI
|
||||
--------------------
|
||||
Install the Lua.efi file into \Efi\Tools. This is the standalone Lua interpreter.
|
||||
Create a directory, \Efi\StdLib\lib\Lua. This is the default location for Lua scripts.
|
||||
|
||||
If desired, copy the files from AppPkg\Applications\Lua\scripts, in the source tree, into
|
||||
\Efi\StdLib\lib\Lua.
|
||||
|
||||
Bugs and Other Issues
|
||||
---------------------
|
||||
EOF characters, ^D or ^Z, are not properly recognized by the console and can't be used to
|
||||
terminate an application. Use os.exit() to exit Lua.
|
||||
533
AppPkg/Applications/Lua/doc/contents.html
Normal file
533
AppPkg/Applications/Lua/doc/contents.html
Normal file
@@ -0,0 +1,533 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Lua 5.2 Reference Manual - contents</TITLE>
|
||||
<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
|
||||
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<STYLE TYPE="text/css">
|
||||
ul {
|
||||
list-style-type: none ;
|
||||
list-style-position: outside ;
|
||||
}
|
||||
</STYLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
|
||||
<HR>
|
||||
<H1>
|
||||
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A>
|
||||
Lua 5.2 Reference Manual
|
||||
</H1>
|
||||
|
||||
<P>
|
||||
The reference manual is the official definition of the Lua language.
|
||||
For a complete introduction to Lua programming, see the book
|
||||
<A HREF="http://www.lua.org/pil/">Programming in Lua</A>.
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html">start</A>
|
||||
·
|
||||
<A HREF="#contents">contents</A>
|
||||
·
|
||||
<A HREF="#index">index</A>
|
||||
<HR>
|
||||
<SMALL>
|
||||
Copyright © 2011–2013 Lua.org, PUC-Rio.
|
||||
Freely available under the terms of the
|
||||
<A HREF="http://www.lua.org/license.html">Lua license</A>.
|
||||
</SMALL>
|
||||
|
||||
<H2><A NAME="contents">Contents</A></H2>
|
||||
<UL style="padding: 0">
|
||||
<LI><A HREF="manual.html">1 – Introduction</A>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#2">2 – Basic Concepts</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#2.1">2.1 – Values and Types</A>
|
||||
<LI><A HREF="manual.html#2.2">2.2 – Environments and the Global Environment</A>
|
||||
<LI><A HREF="manual.html#2.3">2.3 – Error Handling</A>
|
||||
<LI><A HREF="manual.html#2.4">2.4 – Metatables and Metamethods</A>
|
||||
<LI><A HREF="manual.html#2.5">2.5 – Garbage Collection</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#2.5.1">2.5.1 – Garbage-Collection Metamethods</A>
|
||||
<LI><A HREF="manual.html#2.5.2">2.5.2 – Weak Tables</A>
|
||||
</UL>
|
||||
<LI><A HREF="manual.html#2.6">2.6 – Coroutines</A>
|
||||
</UL>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#3">3 – The Language</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#3.1">3.1 – Lexical Conventions</A>
|
||||
<LI><A HREF="manual.html#3.2">3.2 – Variables</A>
|
||||
<LI><A HREF="manual.html#3.3">3.3 – Statements</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#3.3.1">3.3.1 – Blocks</A>
|
||||
<LI><A HREF="manual.html#3.3.2">3.3.2 – Chunks</A>
|
||||
<LI><A HREF="manual.html#3.3.3">3.3.3 – Assignment</A>
|
||||
<LI><A HREF="manual.html#3.3.4">3.3.4 – Control Structures</A>
|
||||
<LI><A HREF="manual.html#3.3.5">3.3.5 – For Statement</A>
|
||||
<LI><A HREF="manual.html#3.3.6">3.3.6 – Function Calls as Statements</A>
|
||||
<LI><A HREF="manual.html#3.3.7">3.3.7 – Local Declarations</A>
|
||||
</UL>
|
||||
<LI><A HREF="manual.html#3.4">3.4 – Expressions</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#3.4.1">3.4.1 – Arithmetic Operators</A>
|
||||
<LI><A HREF="manual.html#3.4.2">3.4.2 – Coercion</A>
|
||||
<LI><A HREF="manual.html#3.4.3">3.4.3 – Relational Operators</A>
|
||||
<LI><A HREF="manual.html#3.4.4">3.4.4 – Logical Operators</A>
|
||||
<LI><A HREF="manual.html#3.4.5">3.4.5 – Concatenation</A>
|
||||
<LI><A HREF="manual.html#3.4.6">3.4.6 – The Length Operator</A>
|
||||
<LI><A HREF="manual.html#3.4.7">3.4.7 – Precedence</A>
|
||||
<LI><A HREF="manual.html#3.4.8">3.4.8 – Table Constructors</A>
|
||||
<LI><A HREF="manual.html#3.4.9">3.4.9 – Function Calls</A>
|
||||
<LI><A HREF="manual.html#3.4.10">3.4.10 – Function Definitions</A>
|
||||
</UL>
|
||||
<LI><A HREF="manual.html#3.5">3.5 – Visibility Rules</A>
|
||||
</UL>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#4">4 – The Application Program Interface</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#4.1">4.1 – The Stack</A>
|
||||
<LI><A HREF="manual.html#4.2">4.2 – Stack Size</A>
|
||||
<LI><A HREF="manual.html#4.3">4.3 – Valid and Acceptable Indices</A>
|
||||
<LI><A HREF="manual.html#4.4">4.4 – C Closures</A>
|
||||
<LI><A HREF="manual.html#4.5">4.5 – Registry</A>
|
||||
<LI><A HREF="manual.html#4.6">4.6 – Error Handling in C</A>
|
||||
<LI><A HREF="manual.html#4.7">4.7 – Handling Yields in C</A>
|
||||
<LI><A HREF="manual.html#4.8">4.8 – Functions and Types</A>
|
||||
<LI><A HREF="manual.html#4.9">4.9 – The Debug Interface</A>
|
||||
</UL>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#5">5 – The Auxiliary Library</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#5.1">5.1 – Functions and Types</A>
|
||||
</UL>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#6">6 – Standard Libraries</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#6.1">6.1 – Basic Functions</A>
|
||||
<LI><A HREF="manual.html#6.2">6.2 – Coroutine Manipulation</A>
|
||||
<LI><A HREF="manual.html#6.3">6.3 – Modules</A>
|
||||
<LI><A HREF="manual.html#6.4">6.4 – String Manipulation</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#6.4.1">6.4.1 – Patterns</A>
|
||||
</UL>
|
||||
<LI><A HREF="manual.html#6.5">6.5 – Table Manipulation</A>
|
||||
<LI><A HREF="manual.html#6.6">6.6 – Mathematical Functions</A>
|
||||
<LI><A HREF="manual.html#6.7">6.7 – Bitwise Operations</A>
|
||||
<LI><A HREF="manual.html#6.8">6.8 – Input and Output Facilities</A>
|
||||
<LI><A HREF="manual.html#6.9">6.9 – Operating System Facilities</A>
|
||||
<LI><A HREF="manual.html#6.10">6.10 – The Debug Library</A>
|
||||
</UL>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#7">7 – Lua Standalone</A>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#8">8 – Incompatibilities with the Previous Version</A>
|
||||
<UL>
|
||||
<LI><A HREF="manual.html#8.1">8.1 – Changes in the Language</A>
|
||||
<LI><A HREF="manual.html#8.2">8.2 – Changes in the Libraries</A>
|
||||
<LI><A HREF="manual.html#8.3">8.3 – Changes in the API</A>
|
||||
</UL>
|
||||
<P>
|
||||
<LI><A HREF="manual.html#9">9 – The Complete Syntax of Lua</A>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="index">Index</A></H2>
|
||||
<TABLE WIDTH="100%">
|
||||
<TR VALIGN="top">
|
||||
<TD>
|
||||
<H3><A NAME="functions">Lua functions</A></H3>
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-_G">_G</A><BR>
|
||||
<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-assert">assert</A><BR>
|
||||
<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
|
||||
<A HREF="manual.html#pdf-dofile">dofile</A><BR>
|
||||
<A HREF="manual.html#pdf-error">error</A><BR>
|
||||
<A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR>
|
||||
<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
|
||||
<A HREF="manual.html#pdf-load">load</A><BR>
|
||||
<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
|
||||
<A HREF="manual.html#pdf-next">next</A><BR>
|
||||
<A HREF="manual.html#pdf-pairs">pairs</A><BR>
|
||||
<A HREF="manual.html#pdf-pcall">pcall</A><BR>
|
||||
<A HREF="manual.html#pdf-print">print</A><BR>
|
||||
<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
|
||||
<A HREF="manual.html#pdf-rawget">rawget</A><BR>
|
||||
<A HREF="manual.html#pdf-rawlen">rawlen</A><BR>
|
||||
<A HREF="manual.html#pdf-rawset">rawset</A><BR>
|
||||
<A HREF="manual.html#pdf-require">require</A><BR>
|
||||
<A HREF="manual.html#pdf-select">select</A><BR>
|
||||
<A HREF="manual.html#pdf-setmetatable">setmetatable</A><BR>
|
||||
<A HREF="manual.html#pdf-tonumber">tonumber</A><BR>
|
||||
<A HREF="manual.html#pdf-tostring">tostring</A><BR>
|
||||
<A HREF="manual.html#pdf-type">type</A><BR>
|
||||
<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-bit32.arshift">bit32.arshift</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.band">bit32.band</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.bnot">bit32.bnot</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.bor">bit32.bor</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.btest">bit32.btest</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.bxor">bit32.bxor</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.extract">bit32.extract</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.lrotate">bit32.lrotate</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.lshift">bit32.lshift</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.replace">bit32.replace</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.rrotate">bit32.rrotate</A><BR>
|
||||
<A HREF="manual.html#pdf-bit32.rshift">bit32.rshift</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
|
||||
<A HREF="manual.html#pdf-coroutine.resume">coroutine.resume</A><BR>
|
||||
<A HREF="manual.html#pdf-coroutine.running">coroutine.running</A><BR>
|
||||
<A HREF="manual.html#pdf-coroutine.status">coroutine.status</A><BR>
|
||||
<A HREF="manual.html#pdf-coroutine.wrap">coroutine.wrap</A><BR>
|
||||
<A HREF="manual.html#pdf-coroutine.yield">coroutine.yield</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-debug.debug">debug.debug</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.getuservalue">debug.getuservalue</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.gethook">debug.gethook</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.getinfo">debug.getinfo</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.getlocal">debug.getlocal</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.getmetatable">debug.getmetatable</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.getregistry">debug.getregistry</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.getupvalue">debug.getupvalue</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.setuservalue">debug.setuservalue</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.sethook">debug.sethook</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.setlocal">debug.setlocal</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.setmetatable">debug.setmetatable</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.setupvalue">debug.setupvalue</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.traceback">debug.traceback</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.upvalueid">debug.upvalueid</A><BR>
|
||||
<A HREF="manual.html#pdf-debug.upvaluejoin">debug.upvaluejoin</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-file:close">file:close</A><BR>
|
||||
<A HREF="manual.html#pdf-file:flush">file:flush</A><BR>
|
||||
<A HREF="manual.html#pdf-file:lines">file:lines</A><BR>
|
||||
<A HREF="manual.html#pdf-file:read">file:read</A><BR>
|
||||
<A HREF="manual.html#pdf-file:seek">file:seek</A><BR>
|
||||
<A HREF="manual.html#pdf-file:setvbuf">file:setvbuf</A><BR>
|
||||
<A HREF="manual.html#pdf-file:write">file:write</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-io.close">io.close</A><BR>
|
||||
<A HREF="manual.html#pdf-io.flush">io.flush</A><BR>
|
||||
<A HREF="manual.html#pdf-io.input">io.input</A><BR>
|
||||
<A HREF="manual.html#pdf-io.lines">io.lines</A><BR>
|
||||
<A HREF="manual.html#pdf-io.open">io.open</A><BR>
|
||||
<A HREF="manual.html#pdf-io.output">io.output</A><BR>
|
||||
<A HREF="manual.html#pdf-io.popen">io.popen</A><BR>
|
||||
<A HREF="manual.html#pdf-io.read">io.read</A><BR>
|
||||
<A HREF="manual.html#pdf-io.stderr">io.stderr</A><BR>
|
||||
<A HREF="manual.html#pdf-io.stdin">io.stdin</A><BR>
|
||||
<A HREF="manual.html#pdf-io.stdout">io.stdout</A><BR>
|
||||
<A HREF="manual.html#pdf-io.tmpfile">io.tmpfile</A><BR>
|
||||
<A HREF="manual.html#pdf-io.type">io.type</A><BR>
|
||||
<A HREF="manual.html#pdf-io.write">io.write</A><BR>
|
||||
|
||||
</TD>
|
||||
<TD>
|
||||
<H3> </H3>
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-math.abs">math.abs</A><BR>
|
||||
<A HREF="manual.html#pdf-math.acos">math.acos</A><BR>
|
||||
<A HREF="manual.html#pdf-math.asin">math.asin</A><BR>
|
||||
<A HREF="manual.html#pdf-math.atan">math.atan</A><BR>
|
||||
<A HREF="manual.html#pdf-math.atan2">math.atan2</A><BR>
|
||||
<A HREF="manual.html#pdf-math.ceil">math.ceil</A><BR>
|
||||
<A HREF="manual.html#pdf-math.cos">math.cos</A><BR>
|
||||
<A HREF="manual.html#pdf-math.cosh">math.cosh</A><BR>
|
||||
<A HREF="manual.html#pdf-math.deg">math.deg</A><BR>
|
||||
<A HREF="manual.html#pdf-math.exp">math.exp</A><BR>
|
||||
<A HREF="manual.html#pdf-math.floor">math.floor</A><BR>
|
||||
<A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR>
|
||||
<A HREF="manual.html#pdf-math.frexp">math.frexp</A><BR>
|
||||
<A HREF="manual.html#pdf-math.huge">math.huge</A><BR>
|
||||
<A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
|
||||
<A HREF="manual.html#pdf-math.log">math.log</A><BR>
|
||||
<A HREF="manual.html#pdf-math.max">math.max</A><BR>
|
||||
<A HREF="manual.html#pdf-math.min">math.min</A><BR>
|
||||
<A HREF="manual.html#pdf-math.modf">math.modf</A><BR>
|
||||
<A HREF="manual.html#pdf-math.pi">math.pi</A><BR>
|
||||
<A HREF="manual.html#pdf-math.pow">math.pow</A><BR>
|
||||
<A HREF="manual.html#pdf-math.rad">math.rad</A><BR>
|
||||
<A HREF="manual.html#pdf-math.random">math.random</A><BR>
|
||||
<A HREF="manual.html#pdf-math.randomseed">math.randomseed</A><BR>
|
||||
<A HREF="manual.html#pdf-math.sin">math.sin</A><BR>
|
||||
<A HREF="manual.html#pdf-math.sinh">math.sinh</A><BR>
|
||||
<A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR>
|
||||
<A HREF="manual.html#pdf-math.tan">math.tan</A><BR>
|
||||
<A HREF="manual.html#pdf-math.tanh">math.tanh</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-os.clock">os.clock</A><BR>
|
||||
<A HREF="manual.html#pdf-os.date">os.date</A><BR>
|
||||
<A HREF="manual.html#pdf-os.difftime">os.difftime</A><BR>
|
||||
<A HREF="manual.html#pdf-os.execute">os.execute</A><BR>
|
||||
<A HREF="manual.html#pdf-os.exit">os.exit</A><BR>
|
||||
<A HREF="manual.html#pdf-os.getenv">os.getenv</A><BR>
|
||||
<A HREF="manual.html#pdf-os.remove">os.remove</A><BR>
|
||||
<A HREF="manual.html#pdf-os.rename">os.rename</A><BR>
|
||||
<A HREF="manual.html#pdf-os.setlocale">os.setlocale</A><BR>
|
||||
<A HREF="manual.html#pdf-os.time">os.time</A><BR>
|
||||
<A HREF="manual.html#pdf-os.tmpname">os.tmpname</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-package.config">package.config</A><BR>
|
||||
<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
|
||||
<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
|
||||
<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>
|
||||
<A HREF="manual.html#pdf-package.path">package.path</A><BR>
|
||||
<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
|
||||
<A HREF="manual.html#pdf-package.searchers">package.searchers</A><BR>
|
||||
<A HREF="manual.html#pdf-package.searchpath">package.searchpath</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-string.byte">string.byte</A><BR>
|
||||
<A HREF="manual.html#pdf-string.char">string.char</A><BR>
|
||||
<A HREF="manual.html#pdf-string.dump">string.dump</A><BR>
|
||||
<A HREF="manual.html#pdf-string.find">string.find</A><BR>
|
||||
<A HREF="manual.html#pdf-string.format">string.format</A><BR>
|
||||
<A HREF="manual.html#pdf-string.gmatch">string.gmatch</A><BR>
|
||||
<A HREF="manual.html#pdf-string.gsub">string.gsub</A><BR>
|
||||
<A HREF="manual.html#pdf-string.len">string.len</A><BR>
|
||||
<A HREF="manual.html#pdf-string.lower">string.lower</A><BR>
|
||||
<A HREF="manual.html#pdf-string.match">string.match</A><BR>
|
||||
<A HREF="manual.html#pdf-string.rep">string.rep</A><BR>
|
||||
<A HREF="manual.html#pdf-string.reverse">string.reverse</A><BR>
|
||||
<A HREF="manual.html#pdf-string.sub">string.sub</A><BR>
|
||||
<A HREF="manual.html#pdf-string.upper">string.upper</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#pdf-table.concat">table.concat</A><BR>
|
||||
<A HREF="manual.html#pdf-table.insert">table.insert</A><BR>
|
||||
<A HREF="manual.html#pdf-table.pack">table.pack</A><BR>
|
||||
<A HREF="manual.html#pdf-table.remove">table.remove</A><BR>
|
||||
<A HREF="manual.html#pdf-table.sort">table.sort</A><BR>
|
||||
<A HREF="manual.html#pdf-table.unpack">table.unpack</A><BR>
|
||||
|
||||
</TD>
|
||||
<TD>
|
||||
<H3>C API</H3>
|
||||
<P>
|
||||
<A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR>
|
||||
<A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR>
|
||||
<A HREF="manual.html#lua_Debug">lua_Debug</A><BR>
|
||||
<A HREF="manual.html#lua_Hook">lua_Hook</A><BR>
|
||||
<A HREF="manual.html#lua_Integer">lua_Integer</A><BR>
|
||||
<A HREF="manual.html#lua_Number">lua_Number</A><BR>
|
||||
<A HREF="manual.html#lua_Reader">lua_Reader</A><BR>
|
||||
<A HREF="manual.html#lua_State">lua_State</A><BR>
|
||||
<A HREF="manual.html#lua_Unsigned">lua_Unsigned</A><BR>
|
||||
<A HREF="manual.html#lua_Writer">lua_Writer</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#lua_absindex">lua_absindex</A><BR>
|
||||
<A HREF="manual.html#lua_arith">lua_arith</A><BR>
|
||||
<A HREF="manual.html#lua_atpanic">lua_atpanic</A><BR>
|
||||
<A HREF="manual.html#lua_call">lua_call</A><BR>
|
||||
<A HREF="manual.html#lua_callk">lua_callk</A><BR>
|
||||
<A HREF="manual.html#lua_checkstack">lua_checkstack</A><BR>
|
||||
<A HREF="manual.html#lua_close">lua_close</A><BR>
|
||||
<A HREF="manual.html#lua_compare">lua_compare</A><BR>
|
||||
<A HREF="manual.html#lua_concat">lua_concat</A><BR>
|
||||
<A HREF="manual.html#lua_copy">lua_copy</A><BR>
|
||||
<A HREF="manual.html#lua_createtable">lua_createtable</A><BR>
|
||||
<A HREF="manual.html#lua_dump">lua_dump</A><BR>
|
||||
<A HREF="manual.html#lua_error">lua_error</A><BR>
|
||||
<A HREF="manual.html#lua_gc">lua_gc</A><BR>
|
||||
<A HREF="manual.html#lua_getallocf">lua_getallocf</A><BR>
|
||||
<A HREF="manual.html#lua_getctx">lua_getctx</A><BR>
|
||||
<A HREF="manual.html#lua_getfield">lua_getfield</A><BR>
|
||||
<A HREF="manual.html#lua_getglobal">lua_getglobal</A><BR>
|
||||
<A HREF="manual.html#lua_gethook">lua_gethook</A><BR>
|
||||
<A HREF="manual.html#lua_gethookcount">lua_gethookcount</A><BR>
|
||||
<A HREF="manual.html#lua_gethookmask">lua_gethookmask</A><BR>
|
||||
<A HREF="manual.html#lua_getinfo">lua_getinfo</A><BR>
|
||||
<A HREF="manual.html#lua_getlocal">lua_getlocal</A><BR>
|
||||
<A HREF="manual.html#lua_getmetatable">lua_getmetatable</A><BR>
|
||||
<A HREF="manual.html#lua_getstack">lua_getstack</A><BR>
|
||||
<A HREF="manual.html#lua_gettable">lua_gettable</A><BR>
|
||||
<A HREF="manual.html#lua_gettop">lua_gettop</A><BR>
|
||||
<A HREF="manual.html#lua_getupvalue">lua_getupvalue</A><BR>
|
||||
<A HREF="manual.html#lua_getuservalue">lua_getuservalue</A><BR>
|
||||
<A HREF="manual.html#lua_insert">lua_insert</A><BR>
|
||||
<A HREF="manual.html#lua_isboolean">lua_isboolean</A><BR>
|
||||
<A HREF="manual.html#lua_iscfunction">lua_iscfunction</A><BR>
|
||||
<A HREF="manual.html#lua_isfunction">lua_isfunction</A><BR>
|
||||
<A HREF="manual.html#lua_islightuserdata">lua_islightuserdata</A><BR>
|
||||
<A HREF="manual.html#lua_isnil">lua_isnil</A><BR>
|
||||
<A HREF="manual.html#lua_isnone">lua_isnone</A><BR>
|
||||
<A HREF="manual.html#lua_isnoneornil">lua_isnoneornil</A><BR>
|
||||
<A HREF="manual.html#lua_isnumber">lua_isnumber</A><BR>
|
||||
<A HREF="manual.html#lua_isstring">lua_isstring</A><BR>
|
||||
<A HREF="manual.html#lua_istable">lua_istable</A><BR>
|
||||
<A HREF="manual.html#lua_isthread">lua_isthread</A><BR>
|
||||
<A HREF="manual.html#lua_isuserdata">lua_isuserdata</A><BR>
|
||||
<A HREF="manual.html#lua_len">lua_len</A><BR>
|
||||
<A HREF="manual.html#lua_load">lua_load</A><BR>
|
||||
<A HREF="manual.html#lua_newstate">lua_newstate</A><BR>
|
||||
<A HREF="manual.html#lua_newtable">lua_newtable</A><BR>
|
||||
<A HREF="manual.html#lua_newthread">lua_newthread</A><BR>
|
||||
<A HREF="manual.html#lua_newuserdata">lua_newuserdata</A><BR>
|
||||
<A HREF="manual.html#lua_next">lua_next</A><BR>
|
||||
<A HREF="manual.html#lua_pcall">lua_pcall</A><BR>
|
||||
<A HREF="manual.html#lua_pcallk">lua_pcallk</A><BR>
|
||||
<A HREF="manual.html#lua_pop">lua_pop</A><BR>
|
||||
<A HREF="manual.html#lua_pushboolean">lua_pushboolean</A><BR>
|
||||
<A HREF="manual.html#lua_pushcclosure">lua_pushcclosure</A><BR>
|
||||
<A HREF="manual.html#lua_pushcfunction">lua_pushcfunction</A><BR>
|
||||
<A HREF="manual.html#lua_pushfstring">lua_pushfstring</A><BR>
|
||||
<A HREF="manual.html#lua_pushglobaltable">lua_pushglobaltable</A><BR>
|
||||
<A HREF="manual.html#lua_pushinteger">lua_pushinteger</A><BR>
|
||||
<A HREF="manual.html#lua_pushlightuserdata">lua_pushlightuserdata</A><BR>
|
||||
<A HREF="manual.html#lua_pushliteral">lua_pushliteral</A><BR>
|
||||
<A HREF="manual.html#lua_pushlstring">lua_pushlstring</A><BR>
|
||||
<A HREF="manual.html#lua_pushnil">lua_pushnil</A><BR>
|
||||
<A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR>
|
||||
<A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR>
|
||||
<A HREF="manual.html#lua_pushthread">lua_pushthread</A><BR>
|
||||
<A HREF="manual.html#lua_pushunsigned">lua_pushunsigned</A><BR>
|
||||
<A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR>
|
||||
<A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR>
|
||||
<A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR>
|
||||
<A HREF="manual.html#lua_rawget">lua_rawget</A><BR>
|
||||
<A HREF="manual.html#lua_rawgeti">lua_rawgeti</A><BR>
|
||||
<A HREF="manual.html#lua_rawgetp">lua_rawgetp</A><BR>
|
||||
<A HREF="manual.html#lua_rawlen">lua_rawlen</A><BR>
|
||||
<A HREF="manual.html#lua_rawset">lua_rawset</A><BR>
|
||||
<A HREF="manual.html#lua_rawseti">lua_rawseti</A><BR>
|
||||
<A HREF="manual.html#lua_rawsetp">lua_rawsetp</A><BR>
|
||||
<A HREF="manual.html#lua_register">lua_register</A><BR>
|
||||
<A HREF="manual.html#lua_remove">lua_remove</A><BR>
|
||||
<A HREF="manual.html#lua_replace">lua_replace</A><BR>
|
||||
<A HREF="manual.html#lua_resume">lua_resume</A><BR>
|
||||
<A HREF="manual.html#lua_setallocf">lua_setallocf</A><BR>
|
||||
<A HREF="manual.html#lua_setfield">lua_setfield</A><BR>
|
||||
<A HREF="manual.html#lua_setglobal">lua_setglobal</A><BR>
|
||||
<A HREF="manual.html#lua_sethook">lua_sethook</A><BR>
|
||||
<A HREF="manual.html#lua_setlocal">lua_setlocal</A><BR>
|
||||
<A HREF="manual.html#lua_setmetatable">lua_setmetatable</A><BR>
|
||||
<A HREF="manual.html#lua_settable">lua_settable</A><BR>
|
||||
<A HREF="manual.html#lua_settop">lua_settop</A><BR>
|
||||
<A HREF="manual.html#lua_setupvalue">lua_setupvalue</A><BR>
|
||||
<A HREF="manual.html#lua_setuservalue">lua_setuservalue</A><BR>
|
||||
<A HREF="manual.html#lua_status">lua_status</A><BR>
|
||||
<A HREF="manual.html#lua_toboolean">lua_toboolean</A><BR>
|
||||
<A HREF="manual.html#lua_tocfunction">lua_tocfunction</A><BR>
|
||||
<A HREF="manual.html#lua_tointeger">lua_tointeger</A><BR>
|
||||
<A HREF="manual.html#lua_tointegerx">lua_tointegerx</A><BR>
|
||||
<A HREF="manual.html#lua_tolstring">lua_tolstring</A><BR>
|
||||
<A HREF="manual.html#lua_tonumber">lua_tonumber</A><BR>
|
||||
<A HREF="manual.html#lua_tonumberx">lua_tonumberx</A><BR>
|
||||
<A HREF="manual.html#lua_topointer">lua_topointer</A><BR>
|
||||
<A HREF="manual.html#lua_tostring">lua_tostring</A><BR>
|
||||
<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
|
||||
<A HREF="manual.html#lua_tounsigned">lua_tounsigned</A><BR>
|
||||
<A HREF="manual.html#lua_tounsignedx">lua_tounsignedx</A><BR>
|
||||
<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
|
||||
<A HREF="manual.html#lua_type">lua_type</A><BR>
|
||||
<A HREF="manual.html#lua_typename">lua_typename</A><BR>
|
||||
<A HREF="manual.html#lua_upvalueid">lua_upvalueid</A><BR>
|
||||
<A HREF="manual.html#lua_upvalueindex">lua_upvalueindex</A><BR>
|
||||
<A HREF="manual.html#lua_upvaluejoin">lua_upvaluejoin</A><BR>
|
||||
<A HREF="manual.html#lua_version">lua_version</A><BR>
|
||||
<A HREF="manual.html#lua_xmove">lua_xmove</A><BR>
|
||||
<A HREF="manual.html#lua_yield">lua_yield</A><BR>
|
||||
<A HREF="manual.html#lua_yieldk">lua_yieldk</A><BR>
|
||||
|
||||
</TD>
|
||||
<TD>
|
||||
<H3>auxiliary library</H3>
|
||||
<P>
|
||||
<A HREF="manual.html#luaL_Buffer">luaL_Buffer</A><BR>
|
||||
<A HREF="manual.html#luaL_Reg">luaL_Reg</A><BR>
|
||||
|
||||
<P>
|
||||
<A HREF="manual.html#luaL_addchar">luaL_addchar</A><BR>
|
||||
<A HREF="manual.html#luaL_addlstring">luaL_addlstring</A><BR>
|
||||
<A HREF="manual.html#luaL_addsize">luaL_addsize</A><BR>
|
||||
<A HREF="manual.html#luaL_addstring">luaL_addstring</A><BR>
|
||||
<A HREF="manual.html#luaL_addvalue">luaL_addvalue</A><BR>
|
||||
<A HREF="manual.html#luaL_argcheck">luaL_argcheck</A><BR>
|
||||
<A HREF="manual.html#luaL_argerror">luaL_argerror</A><BR>
|
||||
<A HREF="manual.html#luaL_buffinit">luaL_buffinit</A><BR>
|
||||
<A HREF="manual.html#luaL_buffinitsize">luaL_buffinitsize</A><BR>
|
||||
<A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR>
|
||||
<A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR>
|
||||
<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR>
|
||||
<A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR>
|
||||
<A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR>
|
||||
<A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR>
|
||||
<A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR>
|
||||
<A HREF="manual.html#luaL_checkoption">luaL_checkoption</A><BR>
|
||||
<A HREF="manual.html#luaL_checkstack">luaL_checkstack</A><BR>
|
||||
<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
|
||||
<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
|
||||
<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
|
||||
<A HREF="manual.html#luaL_checkunsigned">luaL_checkunsigned</A><BR>
|
||||
<A HREF="manual.html#luaL_checkversion">luaL_checkversion</A><BR>
|
||||
<A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR>
|
||||
<A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR>
|
||||
<A HREF="manual.html#luaL_error">luaL_error</A><BR>
|
||||
<A HREF="manual.html#luaL_execresult">luaL_execresult</A><BR>
|
||||
<A HREF="manual.html#luaL_fileresult">luaL_fileresult</A><BR>
|
||||
<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
|
||||
<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
|
||||
<A HREF="manual.html#luaL_getsubtable">luaL_getsubtable</A><BR>
|
||||
<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>
|
||||
<A HREF="manual.html#luaL_len">luaL_len</A><BR>
|
||||
<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
|
||||
<A HREF="manual.html#luaL_loadbufferx">luaL_loadbufferx</A><BR>
|
||||
<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
|
||||
<A HREF="manual.html#luaL_loadfilex">luaL_loadfilex</A><BR>
|
||||
<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
|
||||
<A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR>
|
||||
<A HREF="manual.html#luaL_newlibtable">luaL_newlibtable</A><BR>
|
||||
<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
|
||||
<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
|
||||
<A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR>
|
||||
<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
|
||||
<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
|
||||
<A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR>
|
||||
<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
|
||||
<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
|
||||
<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
|
||||
<A HREF="manual.html#luaL_optunsigned">luaL_optunsigned</A><BR>
|
||||
<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
|
||||
<A HREF="manual.html#luaL_prepbuffsize">luaL_prepbuffsize</A><BR>
|
||||
<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
|
||||
<A HREF="manual.html#luaL_pushresultsize">luaL_pushresultsize</A><BR>
|
||||
<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
|
||||
<A HREF="manual.html#luaL_requiref">luaL_requiref</A><BR>
|
||||
<A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR>
|
||||
<A HREF="manual.html#luaL_setmetatable">luaL_setmetatable</A><BR>
|
||||
<A HREF="manual.html#luaL_testudata">luaL_testudata</A><BR>
|
||||
<A HREF="manual.html#luaL_tolstring">luaL_tolstring</A><BR>
|
||||
<A HREF="manual.html#luaL_traceback">luaL_traceback</A><BR>
|
||||
<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
|
||||
<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
|
||||
<A HREF="manual.html#luaL_where">luaL_where</A><BR>
|
||||
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<HR>
|
||||
<SMALL CLASS="footer">
|
||||
Last update:
|
||||
Tue Mar 12 11:22:18 BRT 2013
|
||||
</SMALL>
|
||||
<!--
|
||||
Last change: revised for Lua 5.2.2
|
||||
-->
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
BIN
AppPkg/Applications/Lua/doc/logo.gif
Normal file
BIN
AppPkg/Applications/Lua/doc/logo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
116
AppPkg/Applications/Lua/doc/lua.1
Normal file
116
AppPkg/Applications/Lua/doc/lua.1
Normal file
@@ -0,0 +1,116 @@
|
||||
.\" $Id: lua.man,v 1.13 2011/11/16 17:16:53 lhf Exp $
|
||||
.TH LUA 1 "$Date: 2011/11/16 17:16:53 $"
|
||||
.SH NAME
|
||||
lua \- Lua interpreter
|
||||
.SH SYNOPSIS
|
||||
.B lua
|
||||
[
|
||||
.I options
|
||||
]
|
||||
[
|
||||
.I script
|
||||
[
|
||||
.I args
|
||||
]
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
.B lua
|
||||
is the standalone Lua interpreter.
|
||||
It loads and executes Lua programs,
|
||||
either in textual source form or
|
||||
in precompiled binary form.
|
||||
(Precompiled binaries are output by
|
||||
.BR luac ,
|
||||
the Lua compiler.)
|
||||
.B lua
|
||||
can be used as a batch interpreter and also interactively.
|
||||
.LP
|
||||
The given
|
||||
.I options
|
||||
are handled in order and then
|
||||
the Lua program in file
|
||||
.I script
|
||||
is loaded and executed.
|
||||
The given
|
||||
.I args
|
||||
are available to
|
||||
.I script
|
||||
as strings in a global table named
|
||||
.BR arg .
|
||||
If no options or arguments are given,
|
||||
then
|
||||
.B "\-v \-i"
|
||||
is assumed when the standard input is a terminal;
|
||||
otherwise,
|
||||
.B "\-"
|
||||
is assumed.
|
||||
.LP
|
||||
In interactive mode,
|
||||
.B lua
|
||||
prompts the user,
|
||||
reads lines from the standard input,
|
||||
and executes them as they are read.
|
||||
If a line does not contain a complete statement,
|
||||
then a secondary prompt is displayed and
|
||||
lines are read until a complete statement is formed or
|
||||
a syntax error is found.
|
||||
If a line starts with
|
||||
.BR '=' ,
|
||||
then
|
||||
.B lua
|
||||
evaluates and displays
|
||||
the values of the expressions in the remainder of the line.
|
||||
.LP
|
||||
At the very start,
|
||||
before even handling the command line,
|
||||
.B lua
|
||||
checks the contents of the environment variables
|
||||
.B LUA_INIT_5_2
|
||||
or
|
||||
.BR LUA_INIT ,
|
||||
in that order.
|
||||
If the contents is of the form
|
||||
.RI '@ filename ',
|
||||
then
|
||||
.I filename
|
||||
is executed.
|
||||
Otherwise, the string is assumed to be a Lua statement and is executed.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BI \-e " stat"
|
||||
execute statement
|
||||
.IR stat .
|
||||
.TP
|
||||
.B \-i
|
||||
enter interactive mode after executing
|
||||
.IR script .
|
||||
.TP
|
||||
.BI \-l " name"
|
||||
execute the equivalent of
|
||||
.IB name =require(' name ')
|
||||
before executing
|
||||
.IR script .
|
||||
.TP
|
||||
.B \-v
|
||||
show version information.
|
||||
.TP
|
||||
.B \-E
|
||||
ignore environment variables.
|
||||
.TP
|
||||
.B \-\-
|
||||
stop handling options.
|
||||
.TP
|
||||
.B \-
|
||||
stop handling options and execute the standard input as a file.
|
||||
.SH "SEE ALSO"
|
||||
.BR luac (1)
|
||||
.br
|
||||
The documentation at lua.org,
|
||||
especially section 7 of the reference manual.
|
||||
.SH DIAGNOSTICS
|
||||
Error messages should be self explanatory.
|
||||
.SH AUTHORS
|
||||
R. Ierusalimschy,
|
||||
L. H. de Figueiredo,
|
||||
W. Celes
|
||||
.\" EOF
|
||||
96
AppPkg/Applications/Lua/doc/lua.css
Normal file
96
AppPkg/Applications/Lua/doc/lua.css
Normal file
@@ -0,0 +1,96 @@
|
||||
html {
|
||||
background-color: #F8F8F8 ;
|
||||
}
|
||||
|
||||
body {
|
||||
border: solid #a0a0a0 1px ;
|
||||
border-radius: 20px ;
|
||||
padding: 26px ;
|
||||
margin: 16px ;
|
||||
color: #000000 ;
|
||||
background-color: #FFFFFF ;
|
||||
font-family: Helvetica, Arial, sans-serif ;
|
||||
text-align: justify ;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
font-family: Verdana, Geneva, sans-serif ;
|
||||
font-weight: normal ;
|
||||
font-style: normal ;
|
||||
}
|
||||
|
||||
h2 {
|
||||
padding-top: 0.4em ;
|
||||
padding-bottom: 0.4em ;
|
||||
padding-left: 0.8em ;
|
||||
padding-right: 0.8em ;
|
||||
background-color: #D0D0FF ;
|
||||
border-radius: 8px ;
|
||||
border: solid #a0a0a0 1px ;
|
||||
}
|
||||
|
||||
h3 {
|
||||
padding-left: 0.5em ;
|
||||
border-left: solid #D0D0FF 1em ;
|
||||
}
|
||||
|
||||
table h3 {
|
||||
padding-left: 0px ;
|
||||
border-left: none ;
|
||||
}
|
||||
|
||||
a:link {
|
||||
color: #000080 ;
|
||||
background-color: inherit ;
|
||||
text-decoration: none ;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
background-color: inherit ;
|
||||
text-decoration: none ;
|
||||
}
|
||||
|
||||
a:link:hover, a:visited:hover {
|
||||
color: #000080 ;
|
||||
background-color: #D0D0FF ;
|
||||
}
|
||||
|
||||
a:link:active, a:visited:active {
|
||||
color: #FF0000 ;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0 ;
|
||||
height: 1px ;
|
||||
color: #a0a0a0 ;
|
||||
background-color: #a0a0a0 ;
|
||||
display: none ;
|
||||
}
|
||||
|
||||
table hr {
|
||||
display: block ;
|
||||
}
|
||||
|
||||
:target {
|
||||
background-color: #F8F8F8 ;
|
||||
padding: 8px ;
|
||||
border: solid #a0a0a0 2px ;
|
||||
border-radius: 8px ;
|
||||
}
|
||||
|
||||
.footer {
|
||||
color: gray ;
|
||||
font-size: x-small ;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
border: solid #a0a0a0 2px ;
|
||||
border-radius: 2em ;
|
||||
-moz-border-radius: 2em ;
|
||||
background-image: url('images/search.png') ;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 4px center ;
|
||||
padding-left: 20px ;
|
||||
height: 2em ;
|
||||
}
|
||||
|
||||
118
AppPkg/Applications/Lua/doc/luac.1
Normal file
118
AppPkg/Applications/Lua/doc/luac.1
Normal file
@@ -0,0 +1,118 @@
|
||||
.\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $
|
||||
.TH LUAC 1 "$Date: 2011/11/16 13:53:40 $"
|
||||
.SH NAME
|
||||
luac \- Lua compiler
|
||||
.SH SYNOPSIS
|
||||
.B luac
|
||||
[
|
||||
.I options
|
||||
] [
|
||||
.I filenames
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
.B luac
|
||||
is the Lua compiler.
|
||||
It translates programs written in the Lua programming language
|
||||
into binary files containing precompiled chunks
|
||||
that can be later loaded and executed.
|
||||
.LP
|
||||
The main advantages of precompiling chunks are:
|
||||
faster loading,
|
||||
protecting source code from accidental user changes,
|
||||
and
|
||||
off-line syntax checking.
|
||||
Precompiling does not imply faster execution
|
||||
because in Lua chunks are always compiled into bytecodes before being executed.
|
||||
.B luac
|
||||
simply allows those bytecodes to be saved in a file for later execution.
|
||||
Precompiled chunks are not necessarily smaller than the corresponding source.
|
||||
The main goal in precompiling is faster loading.
|
||||
.LP
|
||||
In the command line,
|
||||
you can mix
|
||||
text files containing Lua source and
|
||||
binary files containing precompiled chunks.
|
||||
.B luac
|
||||
produces a single output file containing the combined bytecodes
|
||||
for all files given.
|
||||
Executing the combined file is equivalent to executing the given files.
|
||||
By default,
|
||||
the output file is named
|
||||
.BR luac.out ,
|
||||
but you can change this with the
|
||||
.B \-o
|
||||
option.
|
||||
.LP
|
||||
Precompiled chunks are
|
||||
.I not
|
||||
portable across different architectures.
|
||||
Moreover,
|
||||
the internal format of precompiled chunks
|
||||
is likely to change when a new version of Lua is released.
|
||||
Make sure you save the source files of all Lua programs that you precompile.
|
||||
.LP
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-l
|
||||
produce a listing of the compiled bytecode for Lua's virtual machine.
|
||||
Listing bytecodes is useful to learn about Lua's virtual machine.
|
||||
If no files are given, then
|
||||
.B luac
|
||||
loads
|
||||
.B luac.out
|
||||
and lists its contents.
|
||||
Use
|
||||
.B \-l \-l
|
||||
for a full listing.
|
||||
.TP
|
||||
.BI \-o " file"
|
||||
output to
|
||||
.IR file ,
|
||||
instead of the default
|
||||
.BR luac.out .
|
||||
(You can use
|
||||
.B "'\-'"
|
||||
for standard output,
|
||||
but not on platforms that open standard output in text mode.)
|
||||
The output file may be one of the given files because
|
||||
all files are loaded before the output file is written.
|
||||
Be careful not to overwrite precious files.
|
||||
.TP
|
||||
.B \-p
|
||||
load files but do not generate any output file.
|
||||
Used mainly for syntax checking and for testing precompiled chunks:
|
||||
corrupted files will probably generate errors when loaded.
|
||||
If no files are given, then
|
||||
.B luac
|
||||
loads
|
||||
.B luac.out
|
||||
and tests its contents.
|
||||
No messages are displayed if the file loads without errors.
|
||||
.TP
|
||||
.B \-s
|
||||
strip debug information before writing the output file.
|
||||
This saves some space in very large chunks,
|
||||
but if errors occur when running a stripped chunk,
|
||||
then the error messages may not contain the full information they usually do.
|
||||
In particular,
|
||||
line numbers and names of local variables are lost.
|
||||
.TP
|
||||
.B \-v
|
||||
show version information.
|
||||
.TP
|
||||
.B \-\-
|
||||
stop handling options.
|
||||
.TP
|
||||
.B \-
|
||||
stop handling options and process standard input.
|
||||
.SH "SEE ALSO"
|
||||
.BR lua (1)
|
||||
.br
|
||||
The documentation at lua.org.
|
||||
.SH DIAGNOSTICS
|
||||
Error messages should be self explanatory.
|
||||
.SH AUTHORS
|
||||
R. Ierusalimschy,
|
||||
L. H. de Figueiredo,
|
||||
W. Celes
|
||||
.\" EOF
|
||||
27
AppPkg/Applications/Lua/doc/manual.css
Normal file
27
AppPkg/Applications/Lua/doc/manual.css
Normal file
@@ -0,0 +1,27 @@
|
||||
h3 code {
|
||||
font-family: inherit ;
|
||||
font-size: inherit ;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
font-size: 12pt ;
|
||||
}
|
||||
|
||||
span.apii {
|
||||
float: right ;
|
||||
font-family: inherit ;
|
||||
font-style: normal ;
|
||||
font-size: small ;
|
||||
color: gray ;
|
||||
}
|
||||
|
||||
p+h1, ul+h1 {
|
||||
font-style: normal ;
|
||||
padding-top: 0.4em ;
|
||||
padding-bottom: 0.4em ;
|
||||
padding-left: 16px ;
|
||||
margin-left: -16px ;
|
||||
background-color: #D0D0FF ;
|
||||
border-radius: 8px ;
|
||||
border: solid #000080 1px ;
|
||||
}
|
||||
10507
AppPkg/Applications/Lua/doc/manual.html
Normal file
10507
AppPkg/Applications/Lua/doc/manual.html
Normal file
File diff suppressed because it is too large
Load Diff
BIN
AppPkg/Applications/Lua/doc/osi-certified-72x60.png
Normal file
BIN
AppPkg/Applications/Lua/doc/osi-certified-72x60.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
413
AppPkg/Applications/Lua/doc/readme.html
Normal file
413
AppPkg/Applications/Lua/doc/readme.html
Normal file
@@ -0,0 +1,413 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Lua 5.2 readme</TITLE>
|
||||
<LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
|
||||
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<STYLE TYPE="text/css">
|
||||
blockquote, .display {
|
||||
border: solid #a0a0a0 2px ;
|
||||
border-radius: 8px ;
|
||||
padding: 1em ;
|
||||
margin: 0px ;
|
||||
}
|
||||
|
||||
.display {
|
||||
word-spacing: 0.25em ;
|
||||
}
|
||||
|
||||
dl.display dd {
|
||||
padding-bottom: 0.2em ;
|
||||
}
|
||||
|
||||
tt, kbd, code {
|
||||
font-size: 12pt ;
|
||||
}
|
||||
</STYLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
|
||||
<HR>
|
||||
<H1>
|
||||
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
|
||||
Welcome to Lua 5.2
|
||||
</H1>
|
||||
|
||||
<P>
|
||||
<A HREF="#about">about</A>
|
||||
·
|
||||
<A HREF="#install">installation</A>
|
||||
·
|
||||
<A HREF="#changes">changes</A>
|
||||
·
|
||||
<A HREF="#license">license</A>
|
||||
·
|
||||
<A HREF="contents.html">reference manual</A>
|
||||
|
||||
<H2><A NAME="about">About Lua</A></H2>
|
||||
|
||||
<P>
|
||||
Lua is a powerful, fast, lightweight, embeddable scripting language
|
||||
developed by a
|
||||
<A HREF="http://www.lua.org/authors.html">team</A>
|
||||
at
|
||||
<A HREF="http://www.puc-rio.br/">PUC-Rio</A>,
|
||||
the Pontifical Catholic University of Rio de Janeiro in Brazil.
|
||||
Lua is
|
||||
<A HREF="#license">free software</A>
|
||||
used in many products and projects around the world.
|
||||
|
||||
<P>
|
||||
Lua's
|
||||
<A HREF="http://www.lua.org/">official web site</A>
|
||||
provides complete information
|
||||
about Lua,
|
||||
including
|
||||
an
|
||||
<A HREF="http://www.lua.org/about.html">executive summary</A>
|
||||
and
|
||||
updated
|
||||
<A HREF="http://www.lua.org/docs.html">documentation</A>,
|
||||
especially the
|
||||
<A HREF="http://www.lua.org/manual/5.2/">reference manual</A>,
|
||||
which may differ slightly from the
|
||||
<A HREF="contents.html">local copy</A>
|
||||
distributed in this package.
|
||||
|
||||
<H2><A NAME="install">Installing Lua</A></H2>
|
||||
|
||||
<P>
|
||||
Lua is distributed in
|
||||
<A HREF="http://www.lua.org/ftp/">source</A>
|
||||
form.
|
||||
You need to build it before using it.
|
||||
Building Lua should be straightforward
|
||||
because
|
||||
Lua is implemented in pure ANSI C and compiles unmodified in all known
|
||||
platforms that have an ANSI C compiler.
|
||||
Lua also compiles unmodified as C++.
|
||||
The instructions given below for building Lua are for Unix-like platforms.
|
||||
See also
|
||||
<A HREF="#other">instructions for other systems</A>
|
||||
and
|
||||
<A HREF="#customization">customization options</A>.
|
||||
|
||||
<P>
|
||||
If you don't have the time or the inclination to compile Lua yourself,
|
||||
get a binary from
|
||||
<A HREF="http://lua-users.org/wiki/LuaBinaries">LuaBinaries</A>.
|
||||
Try also
|
||||
<A HREF="http://luaforwindows.luaforge.net/">Lua for Windows</A>,
|
||||
an easy-to-use distribution of Lua that includes many useful libraries.
|
||||
|
||||
<H3>Building Lua</H3>
|
||||
|
||||
<P>
|
||||
In most Unix-like platforms, simply do "<KBD>make</KBD>" with a suitable target.
|
||||
Here are the details.
|
||||
|
||||
<OL>
|
||||
<LI>
|
||||
Open a terminal window and move to
|
||||
the top-level directory, which is named <TT>lua-5.2.3</TT>.
|
||||
The Makefile there controls both the build process and the installation process.
|
||||
<P>
|
||||
<LI>
|
||||
Do "<KBD>make</KBD>" and see if your platform is listed.
|
||||
The platforms currently supported are:
|
||||
<P>
|
||||
<P CLASS="display">
|
||||
aix ansi bsd freebsd generic linux macosx mingw posix solaris
|
||||
</P>
|
||||
<P>
|
||||
If your platform is listed, just do "<KBD>make xxx</KBD>", where xxx
|
||||
is your platform name.
|
||||
<P>
|
||||
If your platform is not listed, try the closest one or posix, generic,
|
||||
ansi, in this order.
|
||||
<P>
|
||||
<LI>
|
||||
The compilation takes only a few moments
|
||||
and produces three files in the <TT>src</TT> directory:
|
||||
lua (the interpreter),
|
||||
luac (the compiler),
|
||||
and liblua.a (the library).
|
||||
<P>
|
||||
<LI>
|
||||
To check that Lua has been built correctly, do "<KBD>make test</KBD>"
|
||||
after building Lua. This will run the interpreter and print its version string.
|
||||
</OL>
|
||||
<P>
|
||||
If you're running Linux and get compilation errors,
|
||||
make sure you have installed the <TT>readline</TT> development package.
|
||||
If you get link errors after that,
|
||||
then try "<KBD>make linux MYLIBS=-ltermcap</KBD>".
|
||||
|
||||
<H3>Installing Lua</H3>
|
||||
<P>
|
||||
Once you have built Lua, you may want to install it in an official
|
||||
place in your system. In this case, do "<KBD>make install</KBD>". The official
|
||||
place and the way to install files are defined in the Makefile. You'll
|
||||
probably need the right permissions to install files.
|
||||
|
||||
<P>
|
||||
To build and install Lua in one step, do "<KBD>make xxx install</KBD>",
|
||||
where xxx is your platform name.
|
||||
|
||||
<P>
|
||||
To install Lua locally, do "<KBD>make local</KBD>".
|
||||
This will create a directory <TT>install</TT> with subdirectories
|
||||
<TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>,
|
||||
and install Lua as listed below.
|
||||
|
||||
To install Lua locally, but in some other directory, do
|
||||
"<KBD>make install INSTALL_TOP=xxx</KBD>", where xxx is your chosen directory.
|
||||
|
||||
<DL CLASS="display">
|
||||
<DT>
|
||||
bin:
|
||||
<DD>
|
||||
lua luac
|
||||
<DT>
|
||||
include:
|
||||
<DD>
|
||||
lua.h luaconf.h lualib.h lauxlib.h lua.hpp
|
||||
<DT>
|
||||
lib:
|
||||
<DD>
|
||||
liblua.a
|
||||
<DT>
|
||||
man/man1:
|
||||
<DD>
|
||||
lua.1 luac.1
|
||||
</DL>
|
||||
|
||||
<P>
|
||||
These are the only directories you need for development.
|
||||
If you only want to run Lua programs,
|
||||
you only need the files in bin and man.
|
||||
The files in include and lib are needed for
|
||||
embedding Lua in C or C++ programs.
|
||||
|
||||
<H3><A NAME="customization">Customization</A></H3>
|
||||
<P>
|
||||
Three kinds of things can be customized by editing a file:
|
||||
<UL>
|
||||
<LI> Where and how to install Lua — edit <TT>Makefile</TT>.
|
||||
<LI> How to build Lua — edit <TT>src/Makefile</TT>.
|
||||
<LI> Lua features — edit <TT>src/luaconf.h</TT>.
|
||||
</UL>
|
||||
|
||||
<P>
|
||||
You don't actually need to edit the Makefiles because you may set the
|
||||
relevant variables in the command line when invoking make.
|
||||
Nevertheless, it's probably best to edit and save the Makefiles to
|
||||
record the changes you need.
|
||||
|
||||
<P>
|
||||
On the other hand, if you need to customize some Lua features, you'll need
|
||||
to edit <TT>src/luaconf.h</TT> before building and installing Lua.
|
||||
The edited file will be the one installed, and
|
||||
it will be used by any Lua clients that you build, to ensure consistency.
|
||||
Further customization is available to experts by editing the Lua sources.
|
||||
|
||||
<P>
|
||||
We strongly recommend that you enable dynamic loading in <TT>src/luaconf.h</TT>.
|
||||
This is done automatically for all platforms listed above that have
|
||||
this feature and also for Windows.
|
||||
|
||||
<H3><A NAME="other">Building Lua on other systems</A></H3>
|
||||
|
||||
<P>
|
||||
If you're not using the usual Unix tools, then the instructions for
|
||||
building Lua depend on the compiler you use. You'll need to create
|
||||
projects (or whatever your compiler uses) for building the library,
|
||||
the interpreter, and the compiler, as follows:
|
||||
|
||||
<DL CLASS="display">
|
||||
<DT>
|
||||
library:
|
||||
<DD>
|
||||
lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
|
||||
lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c
|
||||
ltm.c lundump.c lvm.c lzio.c
|
||||
lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c
|
||||
lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c
|
||||
<DT>
|
||||
interpreter:
|
||||
<DD>
|
||||
library, lua.c
|
||||
<DT>
|
||||
compiler:
|
||||
<DD>
|
||||
library, luac.c
|
||||
</DL>
|
||||
|
||||
<P>
|
||||
To use Lua as a library in your own programs you'll need to know how to
|
||||
create and use libraries with your compiler. Moreover, to dynamically load
|
||||
C libraries for Lua you'll need to know how to create dynamic libraries
|
||||
and you'll need to make sure that the Lua API functions are accessible to
|
||||
those dynamic libraries — but <EM>don't</EM> link the Lua library
|
||||
into each dynamic library. For Unix, we recommend that the Lua library
|
||||
be linked statically into the host program and its symbols exported for
|
||||
dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.
|
||||
For Windows, we recommend that the Lua library be a DLL.
|
||||
|
||||
<P>
|
||||
As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize
|
||||
some features before building Lua.
|
||||
|
||||
<H2><A NAME="changes">Changes since Lua 5.1</A></H2>
|
||||
|
||||
<P>
|
||||
Here are the main changes introduced in Lua 5.2.
|
||||
The
|
||||
<A HREF="contents.html">reference manual</A>
|
||||
lists the
|
||||
<A HREF="manual.html#8">incompatibilities</A> that had to be introduced.
|
||||
|
||||
<H3>Main changes</H3>
|
||||
<UL>
|
||||
<LI> yieldable pcall and metamethods
|
||||
<LI> new lexical scheme for globals
|
||||
<LI> ephemeron tables
|
||||
<LI> new library for bitwise operations
|
||||
<LI> light C functions
|
||||
<LI> emergency garbage collector
|
||||
<LI> <CODE>goto</CODE> statement
|
||||
<LI> finalizers for tables
|
||||
</UL>
|
||||
|
||||
Here are the other changes introduced in Lua 5.2:
|
||||
<H3>Language</H3>
|
||||
<UL>
|
||||
<LI> no more fenv for threads or functions
|
||||
<LI> tables honor the <CODE>__len</CODE> metamethod
|
||||
<LI> hex and <CODE>\z</CODE> escapes in strings
|
||||
<LI> support for hexadecimal floats
|
||||
<LI> order metamethods work for different types
|
||||
<LI> no more verification of opcode consistency
|
||||
<LI> hook event "tail return" replaced by "tail call"
|
||||
<LI> empty statement
|
||||
<LI> <CODE>break</CODE> statement may appear in the middle of a block
|
||||
</UL>
|
||||
|
||||
<H3>Libraries</H3>
|
||||
<UL>
|
||||
<LI> arguments for function called through <CODE>xpcall</CODE>
|
||||
<LI> optional 'mode' argument to load and loadfile (to control binary x text)
|
||||
<LI> optional 'env' argument to load and loadfile (environment for loaded chunk)
|
||||
<LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL)
|
||||
<LI> new function <CODE>package.searchpath</CODE>
|
||||
<LI> modules receive their paths when loaded
|
||||
<LI> optional base in <CODE>math.log</CODE>
|
||||
<LI> optional separator in <CODE>string.rep</CODE>
|
||||
<LI> <CODE>file:write</CODE> returns <CODE>file</CODE>
|
||||
<LI> closing a pipe returns exit status
|
||||
<LI> <CODE>os.exit</CODE> may close state
|
||||
<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>
|
||||
<LI> new option 'isrunning' for <CODE>collectgarbage</CODE> and <CODE>lua_gc</CODE>
|
||||
<LI> frontier patterns
|
||||
<LI> <CODE>\0</CODE> in patterns
|
||||
<LI> new option <CODE>*L</CODE> for <CODE>io.read</CODE>
|
||||
<LI> options for <CODE>io.lines</CODE>
|
||||
<LI> <CODE>debug.getlocal</CODE> can access function varargs
|
||||
</UL>
|
||||
|
||||
<H3>C API</H3>
|
||||
<UL>
|
||||
<LI> main thread predefined in the registry
|
||||
<LI> new functions
|
||||
<CODE>lua_absindex</CODE>,
|
||||
<CODE>lua_arith</CODE>,
|
||||
<CODE>lua_compare</CODE>,
|
||||
<CODE>lua_copy</CODE>,
|
||||
<CODE>lua_len</CODE>,
|
||||
<CODE>lua_rawgetp</CODE>,
|
||||
<CODE>lua_rawsetp</CODE>,
|
||||
<CODE>lua_upvalueid</CODE>,
|
||||
<CODE>lua_upvaluejoin</CODE>,
|
||||
<CODE>lua_version</CODE>.
|
||||
<LI> new functions
|
||||
<CODE>luaL_checkversion</CODE>,
|
||||
<CODE>luaL_setmetatable</CODE>,
|
||||
<CODE>luaL_testudata</CODE>,
|
||||
<CODE>luaL_tolstring</CODE>.
|
||||
<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
|
||||
<LI> <CODE>nparams</CODE> and <CODE>isvararg</CODE> available in debug API
|
||||
<LI> new <CODE>lua_Unsigned</CODE>
|
||||
</UL>
|
||||
|
||||
<H3>Implementation</H3>
|
||||
<UL>
|
||||
<LI> max constants per function raised to 2<SUP>26</SUP>
|
||||
<LI> generational mode for garbage collection (experimental)
|
||||
<LI> NaN trick (experimental)
|
||||
<LI> internal (immutable) version of ctypes
|
||||
<LI> simpler implementation for string buffers
|
||||
<LI> parser uses much less C-stack space (no more auto arrays)
|
||||
</UL>
|
||||
|
||||
<H3>Lua standalone interpreter</H3>
|
||||
<UL>
|
||||
<LI> new <CODE>-E</CODE> option to avoid environment variables
|
||||
<LI> handling of non-string error messages
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="license">License</A></H2>
|
||||
<A HREF="http://www.opensource.org/docs/definition.php">
|
||||
<IMG SRC="osi-certified-72x60.png" ALIGN="right" BORDER="0" ALT="[osi certified]" STYLE="padding-left: 30px ;">
|
||||
</A>
|
||||
|
||||
<P>
|
||||
Lua is free software distributed under the terms of the
|
||||
<A HREF="http://www.opensource.org/licenses/mit-license.html">MIT license</A>
|
||||
reproduced below;
|
||||
it may be used for any purpose, including commercial purposes,
|
||||
at absolutely no cost without having to ask us.
|
||||
|
||||
The only requirement is that if you do use Lua,
|
||||
then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.
|
||||
|
||||
For details, see
|
||||
<A HREF="http://www.lua.org/license.html">this</A>.
|
||||
|
||||
<BLOCKQUOTE STYLE="padding-bottom: 0em">
|
||||
Copyright © 1994–2013 Lua.org, PUC-Rio.
|
||||
|
||||
<P>
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
<P>
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
<P>
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
</BLOCKQUOTE>
|
||||
<P>
|
||||
|
||||
<HR>
|
||||
<SMALL CLASS="footer">
|
||||
Last update:
|
||||
Sat Nov 9 22:39:16 BRST 2013
|
||||
</SMALL>
|
||||
<!--
|
||||
Last change: revised for Lua 5.2.3
|
||||
-->
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
12
AppPkg/Applications/Lua/scripts/Fact.lua
Normal file
12
AppPkg/Applications/Lua/scripts/Fact.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- defines a factorial function
|
||||
function fact (n)
|
||||
if n == 0 then
|
||||
return 1
|
||||
else
|
||||
return n * fact(n-1)
|
||||
end
|
||||
end
|
||||
|
||||
print("enter a number:")
|
||||
a = io.read("*number") -- read a number
|
||||
print(fact(a))
|
||||
1
AppPkg/Applications/Lua/scripts/Hello.lua
Normal file
1
AppPkg/Applications/Lua/scripts/Hello.lua
Normal file
@@ -0,0 +1 @@
|
||||
print("Hello UEFI World")
|
||||
187
AppPkg/Applications/Lua/src/Makefile
Normal file
187
AppPkg/Applications/Lua/src/Makefile
Normal file
@@ -0,0 +1,187 @@
|
||||
# Makefile for building Lua
|
||||
# See ../doc/readme.html for installation and customization instructions.
|
||||
|
||||
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
|
||||
|
||||
# Your platform. See PLATS for possible values.
|
||||
PLAT= none
|
||||
|
||||
CC= gcc
|
||||
CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS)
|
||||
LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
|
||||
LIBS= -lm $(SYSLIBS) $(MYLIBS)
|
||||
|
||||
AR= ar rcu
|
||||
RANLIB= ranlib
|
||||
RM= rm -f
|
||||
|
||||
SYSCFLAGS=
|
||||
SYSLDFLAGS=
|
||||
SYSLIBS=
|
||||
|
||||
MYCFLAGS=
|
||||
MYLDFLAGS=
|
||||
MYLIBS=
|
||||
MYOBJS=
|
||||
|
||||
# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
|
||||
|
||||
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
|
||||
|
||||
LUA_A= liblua.a
|
||||
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
|
||||
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
|
||||
ltm.o lundump.o lvm.o lzio.o
|
||||
LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
|
||||
lmathlib.o loslib.o lstrlib.o ltablib.o loadlib.o linit.o
|
||||
BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
|
||||
|
||||
LUA_T= lua
|
||||
LUA_O= lua.o
|
||||
|
||||
LUAC_T= luac
|
||||
LUAC_O= luac.o
|
||||
|
||||
ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
|
||||
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
|
||||
ALL_A= $(LUA_A)
|
||||
|
||||
# Targets start here.
|
||||
default: $(PLAT)
|
||||
|
||||
all: $(ALL_T)
|
||||
|
||||
o: $(ALL_O)
|
||||
|
||||
a: $(ALL_A)
|
||||
|
||||
$(LUA_A): $(BASE_O)
|
||||
$(AR) $@ $(BASE_O)
|
||||
$(RANLIB) $@
|
||||
|
||||
$(LUA_T): $(LUA_O) $(LUA_A)
|
||||
$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
|
||||
|
||||
$(LUAC_T): $(LUAC_O) $(LUA_A)
|
||||
$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) $(ALL_T) $(ALL_O)
|
||||
|
||||
depend:
|
||||
@$(CC) $(CFLAGS) -MM l*.c
|
||||
|
||||
echo:
|
||||
@echo "PLAT= $(PLAT)"
|
||||
@echo "CC= $(CC)"
|
||||
@echo "CFLAGS= $(CFLAGS)"
|
||||
@echo "LDFLAGS= $(SYSLDFLAGS)"
|
||||
@echo "LIBS= $(LIBS)"
|
||||
@echo "AR= $(AR)"
|
||||
@echo "RANLIB= $(RANLIB)"
|
||||
@echo "RM= $(RM)"
|
||||
|
||||
# Convenience targets for popular platforms
|
||||
ALL= all
|
||||
|
||||
none:
|
||||
@echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
|
||||
@echo " $(PLATS)"
|
||||
|
||||
aix:
|
||||
$(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"
|
||||
|
||||
ansi:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI"
|
||||
|
||||
bsd:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E"
|
||||
|
||||
freebsd:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline"
|
||||
|
||||
generic: $(ALL)
|
||||
|
||||
linux:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
|
||||
|
||||
macosx:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" CC=cc
|
||||
|
||||
mingw:
|
||||
$(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \
|
||||
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
|
||||
"SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
|
||||
$(MAKE) "LUAC_T=luac.exe" luac.exe
|
||||
|
||||
posix:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
|
||||
|
||||
solaris:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl"
|
||||
|
||||
# list targets that do not create files (but not all makes understand .PHONY)
|
||||
.PHONY: all $(PLATS) default o a clean depend echo none
|
||||
|
||||
# DO NOT DELETE
|
||||
|
||||
lapi.o: lapi.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \
|
||||
lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h \
|
||||
lvm.h
|
||||
lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
|
||||
lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
|
||||
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
|
||||
lstring.h ltable.h lvm.h
|
||||
lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h
|
||||
ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
|
||||
ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \
|
||||
lfunc.h lstring.h lgc.h ltable.h lvm.h
|
||||
ldo.o: ldo.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \
|
||||
lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h \
|
||||
lstring.h ltable.h lundump.h lvm.h
|
||||
ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
|
||||
lzio.h lmem.h lundump.h
|
||||
lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h \
|
||||
lstate.h ltm.h lzio.h lmem.h
|
||||
lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
|
||||
linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
|
||||
liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \
|
||||
lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
|
||||
lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
|
||||
ltm.h lzio.h lmem.h ldo.h lgc.h
|
||||
loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \
|
||||
lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
|
||||
lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
|
||||
loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
|
||||
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lfunc.h \
|
||||
lstring.h lgc.h ltable.h
|
||||
lstate.o: lstate.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
|
||||
ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h lstring.h \
|
||||
ltable.h
|
||||
lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
|
||||
ltm.h lzio.h lstring.h lgc.h
|
||||
lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
|
||||
ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
|
||||
ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
|
||||
lmem.h lstring.h lgc.h ltable.h
|
||||
lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
luac.o: luac.c lua.h luaconf.h lauxlib.h lobject.h llimits.h lstate.h \
|
||||
ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
|
||||
lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
|
||||
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
|
||||
lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
|
||||
lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
|
||||
lzio.h
|
||||
|
||||
1287
AppPkg/Applications/Lua/src/lapi.c
Normal file
1287
AppPkg/Applications/Lua/src/lapi.c
Normal file
File diff suppressed because it is too large
Load Diff
24
AppPkg/Applications/Lua/src/lapi.h
Normal file
24
AppPkg/Applications/Lua/src/lapi.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
** $Id: lapi.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Auxiliary functions from Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef lapi_h
|
||||
#define lapi_h
|
||||
|
||||
|
||||
#include "llimits.h"
|
||||
#include "lstate.h"
|
||||
|
||||
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
|
||||
"stack overflow");}
|
||||
|
||||
#define adjustresults(L,nres) \
|
||||
{ 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")
|
||||
|
||||
|
||||
#endif
|
||||
959
AppPkg/Applications/Lua/src/lauxlib.c
Normal file
959
AppPkg/Applications/Lua/src/lauxlib.c
Normal file
@@ -0,0 +1,959 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.248.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* This file uses only the official API of Lua.
|
||||
** Any function declared here could be written as an application function.
|
||||
*/
|
||||
|
||||
#define lauxlib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Traceback
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
|
||||
#define LEVELS1 12 /* size of the first part of the stack */
|
||||
#define LEVELS2 10 /* size of the second part of the stack */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** search for 'objidx' in table at index -1.
|
||||
** 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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Error-report functions
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void tag_error (lua_State *L, int narg, int 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... */
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !defined(inspectstat) /* { */
|
||||
|
||||
#if defined(LUA_USE_POSIX)
|
||||
|
||||
#include <sys/wait.h>
|
||||
|
||||
/*
|
||||
** 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"; }
|
||||
|
||||
#else
|
||||
|
||||
#define inspectstat(stat,what) /* no op */
|
||||
|
||||
#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 */
|
||||
}
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Userdata's metatable manipulation
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Argument check functions
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checktype (lua_State *L, int narg, int 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");
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number 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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
|
||||
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);
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Generic Buffer manipulation
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** check whether buffer is using a userdata on the stack as a temporary
|
||||
** buffer
|
||||
*/
|
||||
#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];
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *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 */
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {
|
||||
luaL_buffinit(L, B);
|
||||
return luaL_prepbuffsize(B, sz);
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Reference system
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
/* index of free-list header */
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Load functions
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
typedef struct LoadF {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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++] = (char)c; /* to be read by the parser */
|
||||
} while (*p != '\0');
|
||||
lf->n = 0; /* prefix matched; discard it */
|
||||
return getc(lf->f); /* return next character */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** reads the first character of file 'f' and skips an optional BOM mark
|
||||
** in its beginning plus its first line if it starts with '#'. Returns
|
||||
** true if it skipped the first line. In any case, '*cp' has the
|
||||
** first "valid" character of the file (after the optional BOM and
|
||||
** 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 */
|
||||
}
|
||||
|
||||
|
||||
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++] = (char)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;
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_loadstring (lua_State *L, const char *s) {
|
||||
return luaL_loadbuffer(L, s, strlen(s), 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Compatibility with 5.1 module functions
|
||||
** =======================================================
|
||||
*/
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Find or create a module table with a given name. The function
|
||||
** first looks at the _LOADED table and, if that fails, try a
|
||||
** global variable with that name. In any case, leaves on the stack
|
||||
** 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 */
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
#endif
|
||||
/* }====================================================== */
|
||||
|
||||
/*
|
||||
** set functions from list 'l' into table at top - 'nup'; each
|
||||
** function gets the 'nup' elements at the top as upvalues.
|
||||
** 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 */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** ensure that stack[idx][fname] has a table and push that table
|
||||
** 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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** stripped-down 'require'. Calls 'openf' to open a module,
|
||||
** registers the result in 'package.loaded' table and, if 'glb'
|
||||
** is true, also registers the result in the global table.
|
||||
** 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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API lua_State *luaL_newstate (void) {
|
||||
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);
|
||||
}
|
||||
|
||||
15
AppPkg/Applications/Lua/src/lauxlib.h
Normal file
15
AppPkg/Applications/Lua/src/lauxlib.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/** @file
|
||||
Stub header to allow the "real" headers to reside in StdLib/Include/Lua
|
||||
yet have the Lua sources build without having to change the include
|
||||
directives in each file.
|
||||
|
||||
Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials are licensed and made available under
|
||||
the terms and conditions of the BSD License that accompanies this distribution.
|
||||
The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
**/
|
||||
#include <Lua/lauxlib.h>
|
||||
458
AppPkg/Applications/Lua/src/lbaselib.c
Normal file
458
AppPkg/Applications/Lua/src/lbaselib.c
Normal file
@@ -0,0 +1,458 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.276.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define lbaselib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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 int luaB_type (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int luaB_pairs (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_ipairs (lua_State *L) {
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Generic Read function
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** reserved slot, above all arguments, to hold a copy of the returned
|
||||
** string to avoid it being collected while parsed. 'load' has four
|
||||
** optional arguments (chunk, source name, mode, and environment).
|
||||
*/
|
||||
#define RESERVEDSLOT 5
|
||||
|
||||
|
||||
/*
|
||||
** Reader for generic `load' function: `lua_load' uses the
|
||||
** stack for internal stuff, so the reader cannot change the
|
||||
** stack top. Instead, it keeps its resulting string in a
|
||||
** 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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
static int dofilecont (lua_State *L) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static int pcallcont (lua_State *L) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
static int luaB_tostring (lua_State *L) {
|
||||
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},
|
||||
#if defined(LUA_COMPAT_LOADSTRING)
|
||||
{"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}
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
212
AppPkg/Applications/Lua/src/lbitlib.c
Normal file
212
AppPkg/Applications/Lua/src/lbitlib.c
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
** $Id: lbitlib.c,v 1.18.1.2 2013/07/09 18:01:41 roberto Exp $
|
||||
** Standard library for bitwise operations
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#define lbitlib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
/* number of bits to consider in a number */
|
||||
#if !defined(LUA_NBITS)
|
||||
#define LUA_NBITS 32
|
||||
#endif
|
||||
|
||||
|
||||
#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))
|
||||
|
||||
/* macro to trim extra bits */
|
||||
#define trim(x) ((x) & ALLONES)
|
||||
|
||||
|
||||
/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */
|
||||
#define mask(n) (~((ALLONES << 1) << ((n) - 1)))
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static int b_and (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int b_not (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int b_lshift (lua_State *L) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
static int b_rrot (lua_State *L) {
|
||||
return b_rot(L, -luaL_checkint(L, 2));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** get field and width arguments for field-manipulation functions,
|
||||
** checking whether they are valid.
|
||||
** ('luaL_error' called without 'return' to avoid later warnings about
|
||||
** '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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_bit32 (lua_State *L) {
|
||||
luaL_newlib(L, bitlib);
|
||||
return 1;
|
||||
}
|
||||
|
||||
881
AppPkg/Applications/Lua/src/lcode.c
Normal file
881
AppPkg/Applications/Lua/src/lcode.c
Normal file
@@ -0,0 +1,881 @@
|
||||
/*
|
||||
** $Id: lcode.c,v 2.62.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define lcode_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lcode.h"
|
||||
#include "ldebug.h"
|
||||
#include "ldo.h"
|
||||
#include "lgc.h"
|
||||
#include "llex.h"
|
||||
#include "lmem.h"
|
||||
#include "lobject.h"
|
||||
#include "lopcodes.h"
|
||||
#include "lparser.h"
|
||||
#include "lstring.h"
|
||||
#include "ltable.h"
|
||||
#include "lvm.h"
|
||||
|
||||
|
||||
#define hasjumps(e) ((e)->t != (e)->f)
|
||||
|
||||
|
||||
static int isnumeral(expdesc *e) {
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void luaK_ret (FuncState *fs, int first, int nret) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** returns current `pc' and marks it as a jump target (to avoid wrong
|
||||
** optimizations with consecutive instructions not in the same basic block).
|
||||
*/
|
||||
int luaK_getlabel (FuncState *fs) {
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** check whether list has any jump that do not produce a value
|
||||
** (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 */
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void removevalues (FuncState *fs, int list) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void dischargejpc (FuncState *fs) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void luaK_patchtohere (FuncState *fs, int 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
static int codeextraarg (FuncState *fs, int 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void luaK_reserveregs (FuncState *fs, int n) {
|
||||
luaK_checkstack(fs, n);
|
||||
fs->freereg += (lu_byte)n;
|
||||
}
|
||||
|
||||
|
||||
static void freereg (FuncState *fs, int reg) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int luaK_stringK (FuncState *fs, TString *s) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int boolK (FuncState *fs, int b) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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) */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static void discharge2anyreg (FuncState *fs, expdesc *e) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void luaK_exp2anyregup (FuncState *fs, expdesc *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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
|
||||
lua_assert(!hasjumps(t));
|
||||
t->u.ind.t = (lu_byte)t->u.info;
|
||||
t->u.ind.idx = (short)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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void luaK_fixline (FuncState *fs, int 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 = (lu_byte)base + 1; /* free registers with list values */
|
||||
}
|
||||
|
||||
83
AppPkg/Applications/Lua/src/lcode.h
Normal file
83
AppPkg/Applications/Lua/src/lcode.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
** $Id: lcode.h,v 1.58.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef lcode_h
|
||||
#define lcode_h
|
||||
|
||||
#include "llex.h"
|
||||
#include "lobject.h"
|
||||
#include "lopcodes.h"
|
||||
#include "lparser.h"
|
||||
|
||||
|
||||
/*
|
||||
** Marks the end of a patch list. It is an invalid value both as an absolute
|
||||
** address, and as a list link (would link an element to itself).
|
||||
*/
|
||||
#define NO_JUMP (-1)
|
||||
|
||||
|
||||
/*
|
||||
** 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
|
||||
} BinOpr;
|
||||
|
||||
|
||||
typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
|
||||
|
||||
|
||||
#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_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
|
||||
|
||||
#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);
|
||||
LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);
|
||||
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
|
||||
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
|
||||
LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
|
||||
LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
|
||||
LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);
|
||||
LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);
|
||||
LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
|
||||
LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
|
||||
LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
|
||||
LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
|
||||
LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
|
||||
LUAI_FUNC int luaK_jump (FuncState *fs);
|
||||
LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
|
||||
LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
|
||||
LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
|
||||
LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);
|
||||
LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
|
||||
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);
|
||||
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
|
||||
|
||||
|
||||
#endif
|
||||
155
AppPkg/Applications/Lua/src/lcorolib.c
Normal file
155
AppPkg/Applications/Lua/src/lcorolib.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
** $Id: lcorolib.c,v 1.5.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Coroutine Library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define lcorolib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_cowrap (lua_State *L) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_corunning (lua_State *L) {
|
||||
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}
|
||||
};
|
||||
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_coroutine (lua_State *L) {
|
||||
luaL_newlib(L, co_funcs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
52
AppPkg/Applications/Lua/src/lctype.c
Normal file
52
AppPkg/Applications/Lua/src/lctype.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
** $Id: lctype.c,v 1.11.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** 'ctype' functions for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#define lctype_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lctype.h"
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
#endif /* } */
|
||||
95
AppPkg/Applications/Lua/src/lctype.h
Normal file
95
AppPkg/Applications/Lua/src/lctype.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** 'ctype' functions for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef lctype_h
|
||||
#define lctype_h
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
/*
|
||||
** WARNING: the functions defined here do not necessarily correspond
|
||||
** to the similar functions in the standard C ctype.h. They are
|
||||
** optimized for the specific needs of Lua
|
||||
*/
|
||||
|
||||
#if !defined(LUA_USE_CTYPE)
|
||||
|
||||
#if 'A' == 65 && '0' == 48
|
||||
/* ASCII case: can use its own tables; faster and fixed */
|
||||
#define LUA_USE_CTYPE 0
|
||||
#else
|
||||
/* must use standard C ctype */
|
||||
#define LUA_USE_CTYPE 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#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 MASK(B) (1 << (B))
|
||||
|
||||
|
||||
/*
|
||||
** add 1 to char to allow index -1 (EOZ)
|
||||
*/
|
||||
#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))
|
||||
|
||||
/*
|
||||
** this 'ltolower' only works for alphabetic characters
|
||||
*/
|
||||
#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 /* }{ */
|
||||
|
||||
/*
|
||||
** use standard C ctypes
|
||||
*/
|
||||
|
||||
#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 ltolower(c) (tolower(c))
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#endif
|
||||
|
||||
398
AppPkg/Applications/Lua/src/ldblib.c
Normal file
398
AppPkg/Applications/Lua/src/ldblib.c
Normal file
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
** $Id: ldblib.c,v 1.132.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Interface from Lua to its debug API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ldblib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
#define HOOKKEY "_HKEY"
|
||||
|
||||
|
||||
|
||||
static int db_getregistry (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
static int db_getuservalue (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static void settabss (lua_State *L, const char *i, const char *v) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void settabsb (lua_State *L, const char *i, int v) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int db_getupvalue (lua_State *L) {
|
||||
return auxupvalue(L, 1);
|
||||
}
|
||||
|
||||
|
||||
static int db_setupvalue (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int db_upvalueid (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#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 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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_debug (lua_State *L) {
|
||||
luaL_newlib(L, dblib);
|
||||
return 1;
|
||||
}
|
||||
|
||||
593
AppPkg/Applications/Lua/src/ldebug.c
Normal file
593
AppPkg/Applications/Lua/src/ldebug.c
Normal file
@@ -0,0 +1,593 @@
|
||||
/*
|
||||
** $Id: ldebug.c,v 2.90.1.3 2013/05/16 16:04:15 roberto Exp $
|
||||
** Debug Interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define ldebug_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lapi.h"
|
||||
#include "lcode.h"
|
||||
#include "ldebug.h"
|
||||
#include "ldo.h"
|
||||
#include "lfunc.h"
|
||||
#include "lobject.h"
|
||||
#include "lopcodes.h"
|
||||
#include "lstate.h"
|
||||
#include "lstring.h"
|
||||
#include "ltable.h"
|
||||
#include "ltm.h"
|
||||
#include "lvm.h"
|
||||
|
||||
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
static int currentline (CallInfo *ci) {
|
||||
return getfuncline(ci_func(ci)->p, currentpc(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;
|
||||
}
|
||||
|
||||
|
||||
LUA_API lua_Hook lua_gethook (lua_State *L) {
|
||||
return L->hook;
|
||||
}
|
||||
|
||||
|
||||
LUA_API int lua_gethookmask (lua_State *L) {
|
||||
return L->hookmask;
|
||||
}
|
||||
|
||||
|
||||
LUA_API int lua_gethookcount (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Symbolic Execution
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
static const char *getobjname (Proto *p, int lastpc, int reg,
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
static int filterpc (int pc, int jmptarget) {
|
||||
if (pc < jmptarget) /* is code conditional (inside a jump)? */
|
||||
return -1; /* cannot know who sets that register */
|
||||
else return pc; /* current position sets that register */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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' */
|
||||
int jmptarget = 0; /* any code before this address is conditional */
|
||||
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 = filterpc(pc, jmptarget);
|
||||
break;
|
||||
}
|
||||
case OP_TFORCALL: {
|
||||
if (reg >= a + 2) /* affect all regs above its base */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
break;
|
||||
}
|
||||
case OP_CALL:
|
||||
case OP_TAILCALL: {
|
||||
if (reg >= a) /* affect all registers above base */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
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) {
|
||||
if (dest > jmptarget)
|
||||
jmptarget = dest; /* update 'jmptarget' */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OP_TEST: {
|
||||
if (reg == a) /* jumped code can change 'a' */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (testAMode(op) && reg == a) /* any instruction that set A */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** only ANSI way to check whether a pointer points to an array
|
||||
** (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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
|
||||
if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
|
||||
lua_assert(!ttisstring(p1) && !ttisnumber(p1));
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
34
AppPkg/Applications/Lua/src/ldebug.h
Normal file
34
AppPkg/Applications/Lua/src/ldebug.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
** $Id: ldebug.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Auxiliary functions from Debug Interface module
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef ldebug_h
|
||||
#define ldebug_h
|
||||
|
||||
|
||||
#include "lstate.h"
|
||||
|
||||
|
||||
#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
|
||||
|
||||
#define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
|
||||
|
||||
#define resethookcount(L) (L->hookcount = L->basehookcount)
|
||||
|
||||
/* Active Lua function (given call info) */
|
||||
#define ci_func(ci) (clLvalue((ci)->func))
|
||||
|
||||
|
||||
LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,
|
||||
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);
|
||||
LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
|
||||
const TValue *p2);
|
||||
LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
|
||||
LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
|
||||
|
||||
#endif
|
||||
681
AppPkg/Applications/Lua/src/ldo.c
Normal file
681
AppPkg/Applications/Lua/src/ldo.c
Normal file
@@ -0,0 +1,681 @@
|
||||
/*
|
||||
** $Id: ldo.c,v 2.108.1.3 2013/11/08 18:22:50 roberto Exp $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ldo_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lapi.h"
|
||||
#include "ldebug.h"
|
||||
#include "ldo.h"
|
||||
#include "lfunc.h"
|
||||
#include "lgc.h"
|
||||
#include "lmem.h"
|
||||
#include "lobject.h"
|
||||
#include "lopcodes.h"
|
||||
#include "lparser.h"
|
||||
#include "lstate.h"
|
||||
#include "lstring.h"
|
||||
#include "ltable.h"
|
||||
#include "ltm.h"
|
||||
#include "lundump.h"
|
||||
#include "lvm.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Error-recovery functions
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By
|
||||
** default, Lua handles errors with exceptions when compiling as
|
||||
** C++ code, with _longjmp/_setjmp when asked to use them, and with
|
||||
** longjmp/setjmp otherwise.
|
||||
*/
|
||||
#if !defined(LUAI_THROW)
|
||||
|
||||
#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
|
||||
/* C++ exceptions */
|
||||
#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 */
|
||||
|
||||
#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
|
||||
|
||||
#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
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* chain list of long jump buffers */
|
||||
struct lua_longjmp {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* some space for error handling */
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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' */
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
luaD_checkstack(L, p->maxstacksize); /* check again for new 'base' */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))
|
||||
|
||||
|
||||
/*
|
||||
** 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 = (short)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;
|
||||
n = cast_int(L->top - func) - 1; /* number of real arguments */
|
||||
luaD_checkstack(L, p->maxstacksize);
|
||||
for (; n < p->numparams; n++)
|
||||
setnilvalue(L->top++); /* complete missing arguments */
|
||||
if (!p->is_vararg) {
|
||||
func = restorestack(L, funcr);
|
||||
base = func + 1;
|
||||
}
|
||||
else {
|
||||
base = adjust_varargs(L, p, n);
|
||||
func = restorestack(L, funcr); /* previous call can change stack */
|
||||
}
|
||||
ci = next_ci(L); /* now 'enter' new function */
|
||||
ci->nresults = (short)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 */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Call a function (C or Lua). The function to be called is at *func.
|
||||
** The arguments are on the stack, right after the function.
|
||||
** When returns, all the results are on the stack, starting at the original
|
||||
** 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--;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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' */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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 */
|
||||
}
|
||||
|
||||
|
||||
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 = (lu_byte)status; /* (here it is) */
|
||||
return 1; /* continue running the coroutine */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** signal an error in the call to 'resume', not in the execution of the
|
||||
** coroutine itself. (Such errors should not be handled by any coroutine
|
||||
** 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' */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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);
|
||||
}
|
||||
|
||||
|
||||
LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {
|
||||
int status;
|
||||
int oldnny = L->nny; /* save 'nny' */
|
||||
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 = (unsigned short)oldnny; /* restore 'nny' */
|
||||
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' */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** 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;
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
|
||||
46
AppPkg/Applications/Lua/src/ldo.h
Normal file
46
AppPkg/Applications/Lua/src/ldo.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
** $Id: ldo.h,v 2.20.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef ldo_h
|
||||
#define ldo_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
#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)))
|
||||
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
|
||||
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);
|
||||
LUAI_FUNC void luaD_shrinkstack (lua_State *L);
|
||||
|
||||
LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
|
||||
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
|
||||
|
||||
#endif
|
||||
|
||||
173
AppPkg/Applications/Lua/src/ldump.c
Normal file
173
AppPkg/Applications/Lua/src/ldump.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
** $Id: ldump.c,v 2.17.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** save precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define ldump_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
#include "lundump.h"
|
||||
|
||||
typedef struct {
|
||||
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)
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpChar(int y, DumpState* D)
|
||||
{
|
||||
char x=(char)y;
|
||||
DumpVar(x,D);
|
||||
}
|
||||
|
||||
static void DumpInt(int x, DumpState* D)
|
||||
{
|
||||
DumpVar(x,D);
|
||||
}
|
||||
|
||||
static void DumpNumber(lua_Number x, DumpState* 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#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:
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
DumpChar(bvalue(o),D);
|
||||
break;
|
||||
case LUA_TNUMBER:
|
||||
DumpNumber(nvalue(o),D);
|
||||
break;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void DumpHeader(DumpState* D)
|
||||
{
|
||||
lu_byte h[LUAC_HEADERSIZE];
|
||||
luaU_header(h);
|
||||
DumpBlock(h,LUAC_HEADERSIZE,D);
|
||||
}
|
||||
|
||||
/*
|
||||
** dump Lua function as precompiled chunk
|
||||
*/
|
||||
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;
|
||||
}
|
||||
161
AppPkg/Applications/Lua/src/lfunc.c
Normal file
161
AppPkg/Applications/Lua/src/lfunc.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 2.30.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define lfunc_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lfunc.h"
|
||||
#include "lgc.h"
|
||||
#include "lmem.h"
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
|
||||
|
||||
|
||||
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 *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;
|
||||
}
|
||||
|
||||
|
||||
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 *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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Look for n-th local variable at line `line' in function `func'.
|
||||
** 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 */
|
||||
}
|
||||
|
||||
33
AppPkg/Applications/Lua/src/lfunc.h
Normal file
33
AppPkg/Applications/Lua/src/lfunc.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
** $Id: lfunc.h,v 2.8.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef lfunc_h
|
||||
#define lfunc_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
|
||||
|
||||
#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)))
|
||||
|
||||
|
||||
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
|
||||
LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems);
|
||||
LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems);
|
||||
LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
|
||||
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
|
||||
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);
|
||||
|
||||
|
||||
#endif
|
||||
1220
AppPkg/Applications/Lua/src/lgc.c
Normal file
1220
AppPkg/Applications/Lua/src/lgc.c
Normal file
File diff suppressed because it is too large
Load Diff
157
AppPkg/Applications/Lua/src/lgc.h
Normal file
157
AppPkg/Applications/Lua/src/lgc.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
** $Id: lgc.h,v 2.58.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef lgc_h
|
||||
#define lgc_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
|
||||
/*
|
||||
** Collectable objects may have one of three colors: white, which
|
||||
** means the object is not marked; gray, which means the
|
||||
** object is marked, but its references may be not marked; and
|
||||
** black, which means that the object and all its references are marked.
|
||||
** The main invariant of the garbage collector, while marking objects,
|
||||
** is that a black object can never point to a white one. Moreover,
|
||||
** any gray object must be in a "gray list" (gray, grayagain, weak,
|
||||
** allweak, ephemeron) so that it can be visited again before finishing
|
||||
** the collection cycle. These lists have no meaning when the invariant
|
||||
** is not being enforced (e.g., sweep phase).
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* how much to allocate before next GC step */
|
||||
#if !defined(GCSTEPSIZE)
|
||||
/* ~100 small strings */
|
||||
#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 issweepphase(g) \
|
||||
(GCSsweepstring <= (g)->gcstate && (g)->gcstate <= GCSsweep)
|
||||
|
||||
#define isgenerational(g) ((g)->gckind == KGC_GEN)
|
||||
|
||||
/*
|
||||
** macros to tell when main invariant (white objects cannot point to black
|
||||
** ones) must be kept. During a non-generational collection, the sweep
|
||||
** phase may break the invariant, as objects turned white may point to
|
||||
** still-black objects. The invariant is restored when sweep ends and
|
||||
** all objects are white again. During a generational collection, the
|
||||
** invariant must be kept all times.
|
||||
*/
|
||||
|
||||
#define keepinvariant(g) (isgenerational(g) || g->gcstate <= GCSatomic)
|
||||
|
||||
|
||||
/*
|
||||
** Outside the collector, the state in generational mode is kept in
|
||||
** 'propagate', so 'keepinvariant' is always true.
|
||||
*/
|
||||
#define keepinvariantout(g) \
|
||||
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))
|
||||
|
||||
|
||||
/* 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) */
|
||||
/* bit 7 is currently used by tests (luaL_checkmemory) */
|
||||
|
||||
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
|
||||
|
||||
|
||||
#define iswhite(x) testbits((x)->gch.marked, WHITEBITS)
|
||||
#define isblack(x) testbit((x)->gch.marked, BLACKBIT)
|
||||
#define isgray(x) /* neither white nor black */ \
|
||||
(!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT)))
|
||||
|
||||
#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 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 valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
|
||||
|
||||
#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_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
|
||||
luaC_barrier_(L,obj2gco(p),gcvalue(v)); }
|
||||
|
||||
#define luaC_barrierback(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
|
||||
luaC_barrierback_(L,p); }
|
||||
|
||||
#define luaC_objbarrier(L,p,o) \
|
||||
{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
|
||||
luaC_barrier_(L,obj2gco(p),obj2gco(o)); }
|
||||
|
||||
#define luaC_objbarrierback(L,p,o) \
|
||||
{ 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); }
|
||||
|
||||
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
|
||||
LUAI_FUNC void luaC_step (lua_State *L);
|
||||
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);
|
||||
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);
|
||||
LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);
|
||||
LUAI_FUNC void luaC_checkupvalcolor (global_State *g, UpVal *uv);
|
||||
LUAI_FUNC void luaC_changemode (lua_State *L, int mode);
|
||||
|
||||
#endif
|
||||
67
AppPkg/Applications/Lua/src/linit.c
Normal file
67
AppPkg/Applications/Lua/src/linit.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
** $Id: linit.c,v 1.32.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Initialization of libraries for lua.c and other clients
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** If you embed Lua in your program and need to open the standard
|
||||
** libraries, call luaL_openlibs in your program. If you need a
|
||||
** different set of libraries, copy this file to your project and edit
|
||||
** it to suit your needs.
|
||||
*/
|
||||
|
||||
|
||||
#define linit_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
|
||||
/*
|
||||
** these libs are loaded by lua.c and are readily available to any Lua
|
||||
** 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}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** these libs are preloaded and must be required before used
|
||||
*/
|
||||
static const luaL_Reg preloadedlibs[] = {
|
||||
{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 */
|
||||
}
|
||||
|
||||
666
AppPkg/Applications/Lua/src/liolib.c
Normal file
666
AppPkg/Applications/Lua/src/liolib.c
Normal file
@@ -0,0 +1,666 @@
|
||||
/*
|
||||
** $Id: liolib.c,v 2.112.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** This definition must come before the inclusion of 'stdio.h'; it
|
||||
** should not affect non-POSIX systems
|
||||
*/
|
||||
#if !defined(_FILE_OFFSET_BITS)
|
||||
#define _LARGEFILE_SOURCE 1
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define liolib_c
|
||||
#define LUA_LIB
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
#if !defined(lua_checkmode)
|
||||
|
||||
/*
|
||||
** Check whether 'mode' matches '[rwa]%+?b?'.
|
||||
** Change this macro to accept other modes for 'fopen' besides
|
||||
** 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'))
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** lua_popen spawns a new process connected to the current
|
||||
** one through the file streams.
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
#if !defined(lua_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))
|
||||
|
||||
#elif defined(LUA_WIN) /* }{ */
|
||||
|
||||
#define lua_popen(L,c,m) ((void)L, _popen(c,m))
|
||||
#define lua_pclose(L,file) ((void)L, _pclose(file))
|
||||
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
#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)
|
||||
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#endif /* } */
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** lua_fseek: configuration for longer offsets
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
#if !defined(lua_fseek) && !defined(LUA_ANSI) /* { */
|
||||
|
||||
#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
|
||||
|
||||
#elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
|
||||
&& 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
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
#if !defined(l_fseek) /* default definitions */
|
||||
#define l_fseek(f,o,w) fseek(f,o,w)
|
||||
#define l_ftell(f) ftell(f)
|
||||
#define l_seeknum long
|
||||
#endif
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
#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 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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** When creating file handles, always creates a `closed' file handle
|
||||
** before opening the actual file; so, if there is a memory error, the
|
||||
** 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;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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);
|
||||
}
|
||||
|
||||
|
||||
static LStream *newfile (lua_State *L) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int io_tmpfile (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int io_input (lua_State *L) {
|
||||
return g_iofile(L, IO_INPUT, "r");
|
||||
}
|
||||
|
||||
|
||||
static int io_output (lua_State *L) {
|
||||
return g_iofile(L, IO_OUTPUT, "w");
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static int f_lines (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** READ
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int test_eof (lua_State *L, FILE *f) {
|
||||
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)
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
static int io_read (lua_State *L) {
|
||||
return g_read(L, getiofile(L, IO_INPUT), 1);
|
||||
}
|
||||
|
||||
|
||||
static int f_read (lua_State *L) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static int io_write (lua_State *L) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)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 int io_flush (lua_State *L) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** 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}
|
||||
};
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
530
AppPkg/Applications/Lua/src/llex.c
Normal file
530
AppPkg/Applications/Lua/src/llex.c
Normal file
@@ -0,0 +1,530 @@
|
||||
/*
|
||||
** $Id: llex.c,v 2.63.1.2 2013/08/30 15:49:41 roberto Exp $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
|
||||
#define llex_c
|
||||
#define LUA_CORE
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lctype.h"
|
||||
#include "ldo.h"
|
||||
#include "llex.h"
|
||||
#include "lobject.h"
|
||||
#include "lparser.h"
|
||||
#include "lstate.h"
|
||||
#include "lstring.h"
|
||||
#include "ltable.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
|
||||
#define next(ls) (ls->current = zgetc(ls->z))
|
||||
|
||||
|
||||
|
||||
#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>"
|
||||
};
|
||||
|
||||
|
||||
#define save_and_next(ls) (save(ls, ls->current), next(ls))
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
|
||||
lexerror(ls, msg, ls->t.token);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** creates a new string and anchors it in function's table so that
|
||||
** it will not be collected until the end of the function's compilation
|
||||
** (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);
|
||||
}
|
||||
else { /* string already present */
|
||||
ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */
|
||||
}
|
||||
L->top--; /* remove string from stack */
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** increment line number and skips newline sequence (any of
|
||||
** \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");
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** =======================================================
|
||||
** LEXICAL ANALYZER
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** 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;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(getlocaledecpoint)
|
||||
#define getlocaledecpoint() (localeconv()->decimal_point[0])
|
||||
#endif
|
||||
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* LUA_NUMBER */
|
||||
/*
|
||||
** this function is quite liberal in what it accepts, as 'luaO_str2d'
|
||||
** 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 */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** skip a sequence '[=*[' or ']=*]' and return its number of '='s or
|
||||
** -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;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
int luaX_lookahead (LexState *ls) {
|
||||
lua_assert(ls->lookahead.token == TK_EOS);
|
||||
ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
|
||||
return ls->lookahead.token;
|
||||
}
|
||||
|
||||
78
AppPkg/Applications/Lua/src/llex.h
Normal file
78
AppPkg/Applications/Lua/src/llex.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
** $Id: llex.h,v 1.72.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef llex_h
|
||||
#define llex_h
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
#define FIRST_RESERVED 257
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* WARNING: if you change the order of this enumeration,
|
||||
* 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
|
||||
};
|
||||
|
||||
/* number of reserved words */
|
||||
#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
|
||||
|
||||
|
||||
typedef union {
|
||||
lua_Number r;
|
||||
TString *ts;
|
||||
} SemInfo; /* semantics information */
|
||||
|
||||
|
||||
typedef struct Token {
|
||||
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 */
|
||||
} 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);
|
||||
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);
|
||||
LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
|
||||
LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
|
||||
|
||||
|
||||
#endif
|
||||
309
AppPkg/Applications/Lua/src/llimits.h
Normal file
309
AppPkg/Applications/Lua/src/llimits.h
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
** $Id: llimits.h,v 1.103.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** Limits, basic types, and some other `installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
#ifndef llimits_h
|
||||
#define llimits_h
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
typedef unsigned LUA_INT32 lu_int32;
|
||||
|
||||
typedef LUAI_UMEM lu_mem;
|
||||
|
||||
typedef LUAI_MEM l_mem;
|
||||
|
||||
|
||||
|
||||
/* chars used as small naturals (so that `char' is reserved for characters) */
|
||||
typedef unsigned char lu_byte;
|
||||
|
||||
|
||||
#define MAX_SIZET ((size_t)(~(size_t)0)-2)
|
||||
|
||||
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
|
||||
|
||||
#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
|
||||
|
||||
|
||||
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
||||
|
||||
/*
|
||||
** conversion of pointer to integer
|
||||
** this is for hashing only; there is no problem if the integer
|
||||
** cannot hold the whole pointer value
|
||||
*/
|
||||
#define IntPoint(p) ((unsigned int)(lu_mem)(p))
|
||||
|
||||
|
||||
|
||||
/* type to ensure maximum alignment */
|
||||
#if !defined(LUAI_USER_ALIGNMENT_T)
|
||||
#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
|
||||
#endif
|
||||
|
||||
typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
|
||||
|
||||
|
||||
/* result of a `usual argument conversion' over lua_Number */
|
||||
typedef LUAI_UACNUMBER l_uacNumber;
|
||||
|
||||
|
||||
/* internal assertions for in-house debugging */
|
||||
#if defined(lua_assert)
|
||||
#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); }
|
||||
#else
|
||||
#define lua_assert(c) ((void)0)
|
||||
#define check_exp(c,e) (e)
|
||||
#define lua_longassert(c) ((void)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** assertion for checking API calls
|
||||
*/
|
||||
#if !defined(luai_apicheck)
|
||||
|
||||
#if defined(LUA_USE_APICHECK)
|
||||
#include <assert.h>
|
||||
#define luai_apicheck(L,e) assert(e)
|
||||
#else
|
||||
#define luai_apicheck(L,e) lua_assert(e)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
|
||||
|
||||
|
||||
#if !defined(UNUSED)
|
||||
#define UNUSED(x) ((void)(x)) /* to avoid warnings */
|
||||
#endif
|
||||
|
||||
|
||||
#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))
|
||||
|
||||
|
||||
/*
|
||||
** non-return type
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define l_noret void __attribute__((noreturn))
|
||||
#elif defined(_MSC_VER)
|
||||
#define l_noret void __declspec(noreturn)
|
||||
#else
|
||||
#define l_noret void
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** maximum depth for nested C calls and syntactical nested non-terminals
|
||||
** in a program. (Value must fit in an unsigned short int.)
|
||||
*/
|
||||
#if !defined(LUAI_MAXCCALLS)
|
||||
#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
|
||||
|
||||
|
||||
/*
|
||||
** type for virtual-machine instructions
|
||||
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
|
||||
*/
|
||||
typedef lu_int32 Instruction;
|
||||
|
||||
|
||||
|
||||
/* maximum stack for a Lua function */
|
||||
#define MAXSTACK 250
|
||||
|
||||
|
||||
|
||||
/* minimum size for the string table (must be power of 2) */
|
||||
#if !defined(MINSTRTABSIZE)
|
||||
#define MINSTRTABSIZE 32
|
||||
#endif
|
||||
|
||||
|
||||
/* minimum size for string buffer */
|
||||
#if !defined(LUA_MINBUFFER)
|
||||
#define LUA_MINBUFFER 32
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(lua_lock)
|
||||
#define lua_lock(L) ((void) 0)
|
||||
#define lua_unlock(L) ((void) 0)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_threadyield)
|
||||
#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** these macros allow user-specific actions on threads when you defined
|
||||
** LUAI_EXTRASPACE and need to do something extra when a thread is
|
||||
** created/deleted/resumed/yielded.
|
||||
*/
|
||||
#if !defined(luai_userstateopen)
|
||||
#define luai_userstateopen(L) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstateclose)
|
||||
#define luai_userstateclose(L) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstatethread)
|
||||
#define luai_userstatethread(L,L1) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstatefree)
|
||||
#define luai_userstatefree(L,L1) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstateresume)
|
||||
#define luai_userstateresume(L,n) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstateyield)
|
||||
#define luai_userstateyield(L,n) ((void)L)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** lua_number2int is a macro to convert lua_Number to int.
|
||||
** lua_number2integer is a macro to convert lua_Number to lua_Integer.
|
||||
** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
|
||||
** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
|
||||
** luai_hashnum is a macro to hash a lua_Number value into an integer.
|
||||
** The hash must be deterministic and give reasonable values for
|
||||
** both small and large values (outside the range of integers).
|
||||
*/
|
||||
|
||||
#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_number2unsigned(i,n) \
|
||||
{__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
|
||||
|
||||
|
||||
#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)
|
||||
#else
|
||||
#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]; }
|
||||
|
||||
#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 */
|
||||
|
||||
#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)
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
/* the following definitions always work, but may be slow */
|
||||
|
||||
#if !defined(lua_number2int)
|
||||
#define lua_number2int(i,n) ((i)=(int)(n))
|
||||
#endif
|
||||
|
||||
#if !defined(lua_number2integer)
|
||||
#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
|
||||
#endif
|
||||
|
||||
#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 lua_number2unsigned(i,n) \
|
||||
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
|
||||
#else
|
||||
#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
|
||||
#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))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(ltable_c) && !defined(luai_hashnum)
|
||||
|
||||
#include <float.h>
|
||||
#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; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** macro to control inclusion of some hard tests on stack reallocation
|
||||
*/
|
||||
#if !defined(HARDSTACKTESTS)
|
||||
#define condmovestack(L) ((void)0)
|
||||
#else
|
||||
/* realloc stack keeping its size */
|
||||
#define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
|
||||
#endif
|
||||
|
||||
#if !defined(HARDMEMTESTS)
|
||||
#define condchangemem(L) condmovestack(L)
|
||||
#else
|
||||
#define condchangemem(L) \
|
||||
((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user