Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->

Otto Skorzeny posted:

Things I love -
- transmission line effects
- my life as a dickhead
-

just one test gotta pass tonight, got a +1 here in this loop to write
i write tests *do* *do* *do* *do-do*
we all write tests

Adbot
ADBOT LOVES YOU

Emong
May 31, 2011

perpair to be annihilated


Alright, I'm just starting learning Intel assembly, and I'm trying to write a simple program. The problem is that it segfaults, and I'm either blind, retarded, or fundamentally misunderstanding something because I can't find it.

http://pastebin.com/0iUPjcTE

the chip
Mar 10, 2002

Fun Shoe
How do I make a regular expression that matches either two or three letters at the end of a match, and NOT match any html tags.

For example, I have " - Ben Rothlesbuger | PIT" followed by a </span> tag.
I was able to set up a regex that finds the match if the abbreviation is three letters. If the abbreviation is only two letters, however, it also matches the "<" in the </span> tag.

Any help? This is what I have so far.

" - .* \| ..." minus the quotes.

Vanadium
Jan 8, 2005

I think this instead of "..." should do what you want? [A-Z]{2,3}

Zombywuf
Mar 29, 2008

Emong posted:

Alright, I'm just starting learning Intel assembly, and I'm trying to write a simple program. The problem is that it segfaults, and I'm either blind, retarded, or fundamentally misunderstanding something because I can't find it.

http://pastebin.com/0iUPjcTE

Are you sure you're using the right calling convention? Been a long time since I've done any asm, but everything tends to be pass by register these days.

the chip
Mar 10, 2002

Fun Shoe

Vanadium posted:

I think this instead of "..." should do what you want? [A-Z]{2,3}

drat! How can I buy you a beer or a coffee?

Emong
May 31, 2011

perpair to be annihilated


Zombywuf posted:

Are you sure you're using the right calling convention? Been a long time since I've done any asm, but everything tends to be pass by register these days.

I'm pretty sure I am, since I've been trying to check it against an example program that compiles and runs perfectly.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Your final two printf calls take two arguments, so you should be adding 8 to %esp, not 4. Also, some x86 platforms require 16-byte stack alignment, whereas you're only giving 4-byte alignment. If those aren't enough, use a debugger to figure out *where* your program is segfaulting — if the PC is completely screwed up, I suggest putting a breakpoint before the ret instruction.

Minor point: there's no need to reload speed between those compares.

rjmccall fucked around with this message at 23:36 on Sep 29, 2011

Jewel
May 2, 2009

Gonna repost my question since nobody said anything on it, and I'm still confused :ohdear:

Tw1tchy posted:

Hmh. I've been thinking for the past few weeks on the best way to structure code and objects. Structuring things is my weak point, and I need to get better at it so everything I make doesn't become jumbled messes within the first day.

The goonmade SS13 remake posted this post today: http://spacestation13.com/?cat=4

And it intrigued me. I've been looking into xml a few weeks ago since a lot of games use it, i.e Dwarf Fortress, but after working out how to read it and process it, I still couldn't work out "the best" way to do it in terms of objects.

So their system of:

code:
|---------------|
|   FireAlarm   |
|---------------|
|  Renderable   |
| SoundEmitter  |
| LightEmitter  |
|  Triggerable  |
| WallMountable |
|   Clickable   |
|---------------|
Using

code:
<xml>
<Template name="FireAlarm" fullname="Fire Alarm">
  <Components>
    <SimpleSpriteComponent>
      <State name="on" filename="fire_alarm_off" />
      <State name="off" filename="fire_alarm_on" />
    </SimpleSpriteComponent>
    <SoundEmitter active="false">
      <State name="on" filename="klaxxon" repeat="true" />
    </SoundEmitter>
    <LightEmitter color="#FF0000" active="false" />
    <Triggerable />
    <Clickable />
    <Destructible health="100" />
    <WallMountable height="36" />
    <FireAlarmComponent />
  </Components>
</Template>
</xml>
How would that be, like.. processed in a way. What type of object would be created? Would every object be a single type, inheriting functions from something based off <Clickable /> tags or, like, what. So yeah. I'm fairly confused at how to parse this properly into creating object types, and would like some assistance. Thanks in advance! :)

Emong
May 31, 2011

perpair to be annihilated


rjmccall posted:

Your final two printf calls take two arguments, so you should be adding 8 to %esp, not 4. Also, some x86 platforms require 16-byte stack alignment, whereas you're only giving 4-byte alignment. If those aren't enough, use a debugger to figure out *where* your program is segfaulting — if the PC is completely screwed up, I suggest putting a breakpoint before the ret instruction.

Minor point: there's no need to reload speed between those compares.

Debugger tells me "0x080484a2 in exit ()" which I assume means that the segfault is happening on exit? I've never used a debugger before and I have no idea what I'm doing here.

EDIT:
Hmm, if I replace
LEAVE
CALL exit

with
MOVL $1, %eax
MOVL $11, %ebx
INT $0x80

the segfault stops. Huh.

Emong fucked around with this message at 15:31 on Sep 30, 2011

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Tw1tchy posted:

XML deserialization

The basic goal here is to make objects out of the XML (I'll just go ahead and suggest you avoid XML and aim for JSON or YAML or anything else for readability but whatever). What kind of objects and how the XML attributes and child tags are thrown into the objects is up to you. You could simply throw everything into your language's generic dictionary type, or maybe you specialize a bit and make a class or two for game entities, then parse the XML and make new game entities as you go through a Template tag's attributes and children.

Something like

code:
entities = []
for template in xmlFile.xpath('/Template'):
    entity = new GameEntity()
    for component in template.xpath('/Components/*'):
        if component.children.count > 0:
            make objects based on component's tag name or whatever
        else:
            entity[component.name] = true
    entities.push(entity)
Then maybe you index the templates by name, and make a copy whenever you need one in-game.

Your question was quite generic and I wasn't sure how to answer it, so maybe this helps?

Jewel
May 2, 2009

pokeyman posted:

The basic goal here is to make objects out of the XML (I'll just go ahead and suggest you avoid XML and aim for JSON or YAML or anything else for readability but whatever). What kind of objects and how the XML attributes and child tags are thrown into the objects is up to you. You could simply throw everything into your language's generic dictionary type, or maybe you specialize a bit and make a class or two for game entities, then parse the XML and make new game entities as you go through a Template tag's attributes and children.

Something like

code:
entities = []
for template in xmlFile.xpath('/Template'):
    entity = new GameEntity()
    for component in template.xpath('/Components/*'):
        if component.children.count > 0:
            make objects based on component's tag name or whatever
        else:
            entity[component.name] = true
    entities.push(entity)
Then maybe you index the templates by name, and make a copy whenever you need one in-game.

Your question was quite generic and I wasn't sure how to answer it, so maybe this helps?

Yeah, that definitely does open up my mind a bit to think about it easier. I'll sit down see what I can whip up some time.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Emong posted:

Debugger tells me "0x080484a2 in exit ()" which I assume means that the segfault is happening on exit? I've never used a debugger before and I have no idea what I'm doing here.

The segfault is happening during the call to exit. When writing assembly, you should assume that means you're breaking the preconditions of the call, usually in one of two ways: either you're passing bad arguments or you've fouled up the stack pointer. In this case, both are true.

First, exit takes an argument that you're not passing; generally you want to pass zero, to indicate successful completion. That's not causing your crash, though, because exit doesn't actually do anything with its argument except propagate it onward.

It's easy to detect a screwed-up stack pointer — just look at the crash in the debugger and print the contents of your registers. You should see that %esp is some completely crazy value. If you step through your function, you should see that it's fine until you get to leave. You're not actually setting up a proper call frame in your prologue, so doing a leave just pops some random value into %esp. Not doing the leave should fix that, or you can set up a frame.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Several things are suspect:

- You didn't use ENTER, which means LEAVE will attempt to restore a stack state that was never stored and ruin everything
- Functions are expected to save EBX, ESI, and EDI from the caller
- Your stack cleanup after calls is hosed, you're calling printf with 8 bytes of arguments (two PUSHL) and then adding 4 to ESP instead of 8 during cleanup.

If you're using cdecl, you usually to do this:
code:
enter <local space>, 0
push ebx
push esi
push edi
lea edi,[ebp-<local space>]

... function code ...

pop edi
pop esi
pop ebx
leave
ret 0

OneEightHundred fucked around with this message at 21:34 on Sep 30, 2011

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Emong posted:

I've never used a debugger before and I have no idea what I'm doing here.

You're really handicapping yourself as a programmer if you don't know how to use a debugger. That's probably the most important skill you can be developing right now, so get to it ASAP.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah, what he said. You can kind of get away with for high level languages that have good error event trapping and messaging, but ASM is neither of those.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

OneEightHundred posted:

- Functions are expected to save EBX, ESI, and EDI from the caller

Only if they touch them. The contract is to leave them with their original values, not to save them unconditionally.

pseudorandom name
May 6, 2007

OneEightHundred posted:

- You didn't use ENTER, which means LEAVE will attempt to restore a stack state that was never stored and ruin everything

ENTER and LEAVE don't have to be paired. (And in fact never are in modern code, ENTER is microcoded, while LEAVE is a real instruction.)

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

pseudorandom name posted:

ENTER and LEAVE don't have to be paired
Whatever's at ESP, it's probably not a valid EBP unless you put a valid EBP there, so calling LEAVE and setting EBP to mystery meat may be bad for your program's health.

pseudorandom name
May 6, 2007

Well, yeah, LEAVE obviously expects a specific stack layout. But you don't have to produce that using ENTER. And nobody does, because ENTER is terrible. OTOH, LEAVE isn't, and the general rule of x86 assembly programming is to use the fewest instructions possible (i.e. take advantage of the complex addressing modes, use the instructions that do multiple things, etc.).

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
I thought they all aliased internally anyway. MSVC doesn't output either, it just dumps out push/pop/move instructions, and GCC I think just uses MOV/SUB.

Either way, it is a problem that LEAVE is being called without proper stack setup.

pseudorandom name
May 6, 2007

Sorry, I'm out of date, everybody microcodes LEAVE now. Never use it.

JawnV6
Jul 4, 2004

So hot ...

pseudorandom name posted:

Sorry, I'm out of date, everybody microcodes LEAVE now. Never use it.

I'm pretty sure I'm just confused by your terminology, but what instructions do you think don't get microcoded?

pseudorandom name
May 6, 2007

The ones that aren't listed as "microcoded" in AMD's optimization manual.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





What's the 'best' (friendliest API, most useful, best designed) web server abstraction layer? ie wsgi, rack, et cetera? any language, I need to port one of them to erlang.

tef
May 30, 2004

-> some l-system crap ->
aren't wsgi, psgi, rack roughly the same? the problem is that you might find that the wsgi-style abstraction is a better fit over more imperative, less concurrent languages. i.e instead of passing a context & function in, you could pass a process in which responds to specific messages to manage the connection

that said it seems other people have done straight forward ports of wsgi to erlang already https://github.com/skarab/ewgi

Super Dude
Jan 23, 2005
Do the Jew
edit: Actually I eliminated the majority of my shift/reduce problems with a grammar I'm writing. I am still getting it on the following grammar though. Does anyone know why?

code:
   57 Expr: Expr . Binop Expr
   57     | Expr Binop Expr .
   58     | Expr . Relop Expr
   59     | Expr . Logical_op Expr

    LE_OP       shift, and go to state 120
    GE_OP       shift, and go to state 121
    EQ_OP       shift, and go to state 122
    NE_OP       shift, and go to state 123
    AND_OP      shift, and go to state 124
    OR_OP       shift, and go to state 125
    MUL_ASSIGN  shift, and go to state 126
    DIV_ASSIGN  shift, and go to state 127
    ADD_ASSIGN  shift, and go to state 128
    SUB_ASSIGN  shift, and go to state 129
    LT_OP       shift, and go to state 131
    GT_OP       shift, and go to state 132

    LE_OP       [reduce using rule 57 (Expr)]
    GE_OP       [reduce using rule 57 (Expr)]
    EQ_OP       [reduce using rule 57 (Expr)]
    NE_OP       [reduce using rule 57 (Expr)]
    AND_OP      [reduce using rule 57 (Expr)]
    OR_OP       [reduce using rule 57 (Expr)]
    MUL_ASSIGN  [reduce using rule 57 (Expr)]
    DIV_ASSIGN  [reduce using rule 57 (Expr)]
    ADD_ASSIGN  [reduce using rule 57 (Expr)]
    SUB_ASSIGN  [reduce using rule 57 (Expr)]
    LT_OP       [reduce using rule 57 (Expr)]
    GT_OP       [reduce using rule 57 (Expr)]
    $default    reduce using rule 57 (Expr)

    Binop       go to state 133
    Relop       go to state 134
    Logical_op  go to state 135
For reference, state 120 is
code:
state 120

   74 Relop: LE_OP .

    $default  reduce using rule 74 (Relop)

Super Dude fucked around with this message at 19:03 on Oct 2, 2011

maskenfreiheit
Dec 30, 2004
...

maskenfreiheit fucked around with this message at 23:11 on Oct 2, 2011

Captain Cappy
Aug 7, 2008

You don't reset i to zero once you've gone through your inner while loop. Also, you don't break out of the while loop once you've found the character you were looking for.

Is there a reason you don't just compare the character to the range you want instead of the while loop?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Because you're reusing the loop variable "i" and aren't setting it to 0 before the while loop, so it's re-entering with the value it had the last time it exited the loop.

Also look up "sets", they're an easier way to do this.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
For future reference, pastebin is a handy tool for sharing a large body of text without cluttering your posts.

Super Dude
Jan 23, 2005
Do the Jew
Anyone have an idea about mine?

maskenfreiheit
Dec 30, 2004
.

maskenfreiheit fucked around with this message at 21:27 on Apr 28, 2019

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Any reason why you edited out your post? Kind of annoying when there's already replies to it.

maskenfreiheit
Dec 30, 2004
.

maskenfreiheit fucked around with this message at 21:27 on Apr 28, 2019

maskenfreiheit
Dec 30, 2004
.

maskenfreiheit fucked around with this message at 21:27 on Apr 28, 2019

nielsm
Jun 1, 2009



GregNorc posted:

also, how do I print an integer and a string in the same line?

For example:

print(lower[i] + ": " + counts[i])

would give me an error, (can't concatenate strings) since "lower" is full of strings and "counts" is full of integers.

Depends on whether you're using Python 2.x or Python 3.x, since print was changed from being a keyword/statement to being a regular function in Python 3.

In Python 2:
code:
print lower[i], ":", counts[i]
In Python 3:
code:
print(lower[i], ":", counts[i])
You can also make Python accept the Python 3 function by adding this line to the very top of your source file:
code:
from __future__ import print_function
Alternatively you can use string formatting:
code:
string_var = "{0}: {1}".format(lower[i], counts[i])
print(string_var)  # this will work on either of Python 2 and 3, because there is just one value!
Edit: Eh, used the old string formatting syntax and linked to the new... oops.

nielsm fucked around with this message at 00:13 on Oct 3, 2011

tef
May 30, 2004

-> some l-system crap ->

Super Dude posted:

edit: Actually I eliminated the majority of my shift/reduce problems with a grammar I'm writing. I am still getting it on the following grammar though. Does anyone know why?

code:
   57 Expr: Expr . Binop Expr
   57     | Expr Binop Expr .
   58     | Expr . Relop Expr
   59     | Expr . Logical_op Expr

Have you defined any precedence or associativity for the binary operators?

Super Dude
Jan 23, 2005
Do the Jew

tef posted:

Have you defined any precedence or associativity for the binary operators?

code:
%left LE_OP GE_OP
%left EQ_OP NE_OP
%left AND_OP OR_OP
%left LT_OP GT_OP
%left ADD_ASSIGN SUB_ASSIGN
%left MUL_ASSIGN DIV_ASSIGN

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
It would help some if you pastebin'd your entire grammar

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply