Comments (9)
Thank you, I'll take a look over the weekend. Get better!
from tealang.
I confirmed there is problem is slots allocation in functions, it might overwrite variables that used after in parent function scopes. Making functions inline (inline function abc()
) should help as a temporary workaround.
from tealang.
And so the second time I call that function, I always end up with 1 for that number instead of what it was.
You are right, it uses scratch space for args passing (since in tealang v1 functions were inlined and arguments were treated as its local vars). Non-inlined function use the same approach but re-allocate local vars on each call based on a higher var address (slot) in parent scope. Could give an example demonstrating the issue?
is there a way to discard a return value, or not return anything?
No, because this would promote using global vars and often is considered as a bad practice.
from tealang.
Unfortunately when I went to clean up the example, I changed something and it was still doing something unexpected, but different from what happened before maybe. And I have a really serious sinus headache and need to sleep. Not to include too much irrelevant information.
The last thing I changed was using three local variables predeclared, rather than reusing a variable multiple times -- not sure that is the same issue I had before. That allowed me to get the expected answer though.
let _ = 0
function newl() {
apps[0].put("dbg", concat(apps[0].get("dbg"), "\x0d" ))
return 1
}
function log_(msg) {
apps[0].put("dbg", concat(apps[0].get("dbg"), msg))
return 1
}
function log(msg) {
apps[0].put("dbg", concat(apps[0].get("dbg"), msg))
let x = newl()
return 1
}
function printch(digit) {
let ascii = digit + 48
let discard = log_(" ")
let dbg = apps[0].get("dbg")
apps[0].put("dbg",setbyte(apps[0].get("dbg"), len(dbg)-1, ascii))
return 1
}
function printFirstDigit(nn) {
if nn >= 100 {
_= printch(nn / 100)
return nn % 100
}
if nn >= 10 {
_= printch(nn / 10)
return nn % 10
}
_= printch(nn)
return 9999
}
// this version works
function printNum(num) {
_= log("Start of printNum.")
let a = 0
let b = 0
let c = 0
a = printFirstDigit(num)
if a != 9999 {
b = printFirstDigit(a)
}
if b != 9999 {
c = printFirstDigit(b)
}
return 1
}
function logic() {
apps[0].put("dbg", "")
_= printNum(74)
return 1
}
When it was like the following, it was not returning the ASCII digits properly, I think it was just repeating them:
// does not work
function printNum(num) {
_= log("Start of printNum.")
let left = printFirstDigit(num)
if left != 9999 {
left = printFirstDigit(left)
}
if left != 9999 {
left = printFirstDigit(left)
}
return 1
}
from tealang.
By the way, when I tried that same function with shiqizng's version (as of this moment), it gave me a different answer (75) which seems closer but also is not correct. Yours gives 77. The other version of the function with a, b, c outputs 74 correctly.
from tealang.
Ok.. so I did not know that Tealang supported inline functions. Did not see it in the documentation. But I can confirm, I started using a macro preprocessor called gpp yesterday on my 'rollstats' test project, because I wanted to save a few instruction executions since I was running out of the 700 or so allocated. When I converted a function into a macro (so that it was inlined) I was able to get the correct answer to my sum (which I mentioned in my other issue).
from tealang.
tealang has functions since v1 even before TEAL v4 callsub/retsub
so I had to make them inline. With latest patches I made this explicit with inline
keyword.
from tealang.
Ok thanks for reminding me about the inline then. My silly dice roller thing was just a test to play around. I believe that now I know about the cause and inlining I can go full speed ahead with the rest of our auction contracts in Tealang. As far as I know the thing with byte[] vs uint hopefully is not a blocker related to that.
from tealang.
Fixed in #28
from tealang.
Related Issues (14)
- Example comparing global get to transaction address? HOT 2
- Implement type cast HOT 1
- Building issues HOT 4
- Implement `void` keyword
- Adding 4 numbers = wrong answer? HOT 4
- Project going forward? HOT 3
- PRs in shiqizng fork HOT 1
- TEAL v5 HOT 1
- TEAL v6 HOT 2
- Support gload(s)(s), load(s), store(s)
- TEAL v4
- Not mentioned in documentation? HOT 5
- TEAL v3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tealang.